nodejs module.js:340 抛出错误;使用 WebSocket 节点
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14807232/
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
nodejs module.js:340 throw err; using WebSocket-Node
提问by user63898
im new to this , i installed the nodejs with the installer in windows. then i installed the WebSocket-Node module with this command: npm install websocket , looks like successful install .
我是新手,我在 Windows 中使用安装程序安装了 nodejs。然后我使用以下命令安装了 WebSocket-Node 模块: npm install websocket ,看起来安装成功。
npm http GET https://registry.npmjs.org/websocket
npm http 200 https://registry.npmjs.org/websocket
npm http GET https://registry.npmjs.org/websocket/-/websocket-1.0.8.tgz
npm http 200 https://registry.npmjs.org/websocket/-/websocket-1.0.8.tgz
> [email protected] install D:\dev\html5\books\bumper\node_modules\websocket
> node install.js
[websocket v1.0.8] Attempting to compile native extensions.
[websocket v1.0.8] Native extension compilation successful!
[email protected] node_modules\websocket
it installed the nodejs in this location :
它在这个位置安装了 nodejs:
c:\Program Files (x86)\nodejs\
c:\Program Files (x86)\nodejs\
now i try to execute the server.js example from https://github.com/Worlize/WebSocket-Nodeim getting this error:
现在我尝试从https://github.com/Worlize/WebSocket-Node执行 server.js 示例, 我收到此错误:
D:\dev\html5\books\bumper>node server.js
module.js:340
throw err;
^
Error: Cannot find module '/path/to/websocket'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at Object.<anonymous> (D:\dev\html5\books\bumper\server.js:3:23)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:492:10)
also the module is installed in the project root did not in the nodejs dir , is it ok?
该模块也安装在项目根目录中,而不是在 nodejs 目录中,可以吗?
采纳答案by Pascal Belloncle
Based on the error message it looks like the require line looks like this
根据错误消息,require 行看起来像这样
var websocket = require('/path/to/websocket');
Once you've installed something with npm, you can use just the module name:
一旦你用 npm 安装了一些东西,你就可以只使用模块名称:
var websocket = require('websocket');

