javascript 找不到模块“温斯顿”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19386439/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot find module 'winston'
提问by hba
I wrote a little module that uses winston to log stuff.
我写了一个使用 winston 来记录东西的小模块。
I used sudo npm install -g winston
(it is on a vm...so i'm not too concerned with sudo, etc.
我用过sudo npm install -g winston
(它在虚拟机上……所以我不太关心 sudo 等。
Log from npm:
从 npm 登录:
[email protected] /usr/local/lib/node_modules/winston
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
When I try to run my module in node I get:
当我尝试在节点中运行我的模块时,我得到:
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)
System versions: ubuntu node -v = v0.11.7-pre npm -v = 1.3.8
系统版本:ubuntu node -v = v0.11.7-pre npm -v = 1.3.8
P.S. I tried this on my home laptop (another ubuntu vm) and worked.
PS 我在我的家用笔记本电脑(另一个 ubuntu vm)上试过这个并且工作。
回答by Tom Grant
If the suggestion of setting the class path hasn't worked, it might likely be that you need to use an npm link. See: http://blog.nodejs.org/2011/04/06/npm-1-0-link/
如果设置类路径的建议不起作用,则可能是您需要使用 npm 链接。见:http: //blog.nodejs.org/2011/04/06/npm-1-0-link/
For winston goto the root folder of your script and use the command:
对于 winston,请转到脚本的根文件夹并使用以下命令:
npm link winston
回答by fakewaffle
You probably need to export NODE_PATH=/usr/local/lib/node_modules
, where /usr/local/lib/node_modules
is the path where your node modules are globally installed.
您可能需要export NODE_PATH=/usr/local/lib/node_modules
,/usr/local/lib/node_modules
全局安装节点模块的路径在哪里。
回答by Mark
In general, missing modules should be solved by setting NODE_PATH
as @fakewaffle says. Assuming they're installed of course.
一般来说,丢失的模块应该通过设置NODE_PATH
为@fakewaffle 所说的来解决。当然,假设它们已安装。
But for winston
, this didn't work for me. For some reason, I had to update file permissions:
但是对于winston
,这对我不起作用。出于某种原因,我不得不更新文件权限:
chmod o+rx -R /pathto/node_modules/winston
I don't know why it permissions get set incorrectly. This solution is for Ubuntu, presumably it works for other linuxes but not Windows.
我不知道为什么它的权限设置不正确。此解决方案适用于 Ubuntu,大概适用于其他 linux,但不适用于 Windows。
回答by Mohanraj M
npm WARN [email protected] requires a peer of winston@^2 || ^3 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] 需要 winston@^2 的同级 || ^3 但没有安装。您必须自己安装对等依赖项。
and i have removed node_modules folderand made npm installto dependency. it worked
我已经删除了 node_modules 文件夹并将npm install 安装到依赖项。有效
Note:check before deleting the that you have package.json
注意:删除之前检查你有 package.json
"winston": "^2.4.1", "winston-daily-rotate-file": "^3.0.0"
"winston": "^2.4.1", "winston-daily-rotate-file": "^3.0.0"