11
5

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.

npm install request してもnpm install -g requestしてもCannot find module 'request'

Posted at

問題

npm install requestしてもnpm install -g requestしても、~/.bash_profileにグローバルなパスを追加してもCannot find module 'request'になるという事象が起きた。

$ node app.js 
module.js:57
    throw err;
    ^
Error: Cannot find module 'request'

解決策

npm install request --save

原因

npm install requestしたのに関わらず、package.jsonのdependenciesにはrequestモジュールが含まれていなかった。その原因は謎。なので--saveオプションを指定して、package.jsonのdependenciesにバージョン付きで書き込んであげた。

学んだこと

Error: Cannot find module ~ ってエラーが出力されたら、npm installを既に叩いていても、
package.jsonの中身を確認する。確認して存在していれば~/.bash_profile辺りを確認してみる。

参考記事

node.js: cannot find module 'request'
npm install -gでグローバルインストールしたのに見つけてくれない

11
5
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
11
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?