我刚刚安装了node.js + microsoft Visual,以便能够安装websocket,它安装得很好:
C:\Users\Administrator>npm install websocket
npm http GET https://registry.npmjs.org/websocket
npm http 304 https://registry.npmjs.org/websocket
> [email protected] /cdn-cgi/l/email-protection install C:\Users\Administrator\node_modules\websocket
> node install.js
[websocket v1.0.8] Attempting to compile native extensions.
[websocket v1.0.8] Native extension compilation successful!
web[email protected] /cdn-cgi/l/email-protection node_modules\websocket
C:\Users\Administrator>
现在我正在尝试使用以下命令运行脚本:
var WebSocketServer = require('websocket').Server;
我得到这个:
C:\Users\Administrator>node C:\server\src\main.js
module.js:340
throw err;
^
Error: Cannot find module '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> (C:\server\src\main.js:2: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)
C:\Users\Administrator>
任何帮助将不胜感激,我已经尝试安装多次,我尝试全局安装它(-g 标签)。
请注意,如果您全局安装了 NPM 模块(使用-g
选项)并没有告诉node
使用全局模块路径来解决需求。
在 Linux 上我安装了websocket
全局模块:
$ sudo npm install -g 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] /cdn-cgi/l/email-protection install /usr/local/lib/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] /cdn-cgi/l/email-protection /usr/local/lib/node_modules/websocket
之后我必须导出NODE_PATH
环境变量指向上面输出中提到的路径:
export NODE_PATH=/usr/local/lib/node_modules
在这之后:
$ node
> require('websocket')
{ server:
{ [Function: WebSocketServer]
super_: { [Function: EventEmitter] listenerCount: [Function] } },
...
希望这可以帮助那些搜索此错误消息的人。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)