找不到模块'winston'

我写了一个使用winston来logging东西的小模块。

我用sudo npm install -g winston (这是在vm上…所以我不太关心sudo等等

从npmlogging:

 winston@0.7.2 /usr/local/lib/node_modules/winston ├── cycle@1.0.2 ├── stack-trace@0.0.7 ├── eyes@0.1.8 ├── colors@0.6.2 ├── async@0.2.9 ├── pkginfo@0.3.0 └── request@2.16.6 (forever-agent@0.2.0, aws-sign@0.2.0, tunnel-agent@0.2.0, oauth-sign@0.2.0, json-stringify-safe@3.0.0, cookie-jar@0.2.0, node-uuid@1.4.1, mime@1.2.11, qs@0.5.6, hawk@0.10.2, form-data@0.0.10) 

当我尝试在节点中运行我的模块时,我得到:

 Error: Cannot find module 'winston' at Function.Module._resolveFilename (module.js:331:15) at Function.Module._load (module.js:273:25) at Module.require (module.js:357:17) at require (module.js:373:17) at Object.<anonymous> (/home/name/Code/neon/neon-js-spike/logger.js:2:9) at Module._compile (module.js:449:26) at Object.Module._extensions..js (module.js:467:10) at Module.load (module.js:349:32) at Function.Module._load (module.js:305:12) at Module.require (module.js:357:17) 

系统版本:ubuntu node -v = v0.11.7-pre npm -v = 1.3.8

PS我在我的家庭笔记本电脑(另一个Ubuntu的虚拟机)上试过这个工作。

您可能需要export NODE_PATH=/usr/local/lib/node_modules ,其中/usr/local/lib/node_modules是全局安装节点模块的path。

如果设置类path的build议不起作用,则可能是您需要使用npm链接。 请参阅: http : //blog.nodejs.org/2011/04/06/npm-1-0-link/

对于winston转到您的脚本的根文件夹,并使用命令:

 npm link winston 

一般来说,缺less的模块应该通过设置NODE_PATH来解决,就像@fakewaffle所说的那样。 假设他们当然安装了。

但是对winston ,这对我并不适用。 出于某种原因,我不得不更新文件权限:

 chmod o+rx -R /pathto/node_modules/winston 

我不知道为什么它的权限设置不正确。 这个解决scheme适用于Ubuntu,大概它适用于其他Linux,但不适用于Windows。