this problem,と似たような場合、npmでモジュールをインストールしましたが、require('module')
が見つかりません。ノードで、require()がnpmでインストールしたばかりのモジュールを見つけられないのはなぜですか?
my-machine:projectname me$ npm install express-csrf
npm info it worked if it ends with ok
npm info version 0.2.1
npm info install [email protected]
npm info activate [email protected]
npm info build Success: [email protected]
npm ok
これまでのところ、とても良いです。しかし、その後...
my-machine:projectname me$ node
> require('express-csrf')
Error: Cannot find module 'express-csrf'
at Function._resolveFilename (module.js:317:11)
at Function._load (module.js:262:25)
at require (module.js:346:19)
at [object Context]:1:1
at Interface.<anonymous> (repl.js:171:22)
at Interface.emit (events.js:64:17)
at Interface._onLine (readline.js:153:10)
at Interface._line (readline.js:408:8)
at Interface._ttyWrite (readline.js:585:14)
at ReadStream.<anonymous> (readline.js:73:12)
NPMは、パッケージがあると言う:新しいモジュールは/ usr/local/lib /ノード・ディレクトリーには表示されませんが、それがないことを
my-machine:projectname me$ npm ls express-csrf
npm info it worked if it ends with ok
npm info version 0.2.1
[email protected] active installed
npm ok
注意/usr/local/lib/node/.npm
の下に表示されmy-machine:projectname me$ ls /usr/local/lib/node/express-csrf*
ls: /usr/local/lib/node/express-csrf*: No such file or directory
my-machine:projectname me$ ls /usr/local/lib/node/.npm/express-csrf*
0.3.3 active
アップデート:私は完全にそのようなrequire
文でパスを修飾するとき、すべてが動作することを言及する必要があります:
require('/usr/local/lib/node/.npm/express-csrf/active/package/index.js')
を必要がありますか?環境の不一致のためパスが多少異なるかもしれませんか? – Thilo
npmのバージョンは1.0.103ですが、あなたのバージョンは古くなっています... –
http://stackoverflow.com/questions/15471965/what-will-be-the-difference-in-requiremypackage-js-and-ありがとう、クリス。#15471995#01471995 –