4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

TypeError: require.extensions.hasOwnProperty is not a function [gulp実行時のエラー対応]

Posted at

以前作成した、プロジェクトを修正するのに当たって、gulpコマンドを叩いた時にタイトルのようなエラー文が出た時の対応策です。

このエラー、結構見受けられるらしいですが、ググっても解決策が日本語では見つからなかったのでかき残しておきます。

エラー例はこんな感じ。(ここではLaravelーelixirの表記が出ていますが、関係ないです。)

TypeError: require.extensions.hasOwnProperty is not a function
    at requireDir (/Users/user/workspace/project/node_modules/laravel-elixir/node_modules/require-dir/index.js:93:37)
    at Elixir (/Users/user/workspace/project/node_modules/laravel-elixir/index.js:2:27)
    at Object.<anonymous> (/Users/user/workspace/project/gulpfile.js:15:1)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)

原因

node.jsのバージョンアップによるものです。
僕はこのプロジェクトには途中から修正で関わったのですが、製作されたのは数年前らしく、僕のnodeのバージョンよりも古いもので作られていたみたいです。

解決方法

node.jsのバージョンを切り替えるのに便利なnvmを使用しましょう。

# nvmのインストール
git clone git://github.com/creationix/nvm.git ~/.nvm

# 設定の読込(こちらでうまくいかない場合は手動でバッシュを書き換えてください。)
echo "source ~/.nvm/nvm.sh" >> ~/.bash_profile && source ~/.bash_profile

# nvmのバージョン確認
nvm --version

# install 可能なnode確認
nvm ls-remote

# nvmから v6のインストール(v6.11.0がもっとも安定してるぽい)
# 僕の時はv6が該当しました。node-v8以上を使用していることでこのエラーに出会っているのであれば、
# おそらくv6を使用すればいけるんじゃないかと思います。
nvm install 6.11.0

# インストールされたか確認
node -v

# gulp実行
gulp

参考元

https://github.com/tjunnone/npm-check-updates/issues/367
https://github.com/tjunnone/npm-check-updates/issues/363#issuecomment-308452577

もしも間違い・ご指摘ありましたらよろしくお願いします。

4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?