Ubuntu 16.04-尽管已在全球范围内安装,nodejs仍找不到模块

时间:2019-01-29 14:23:00

标签: node.js

新的Ubuntu 16.04安装。按照官方说明安装了nodejs 10.15

# curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
# apt-get install nodejs

然后在全球安装ws

# npm install -g ws
+ ws@6.1.3
updated 1 package in 0.374s

然后在js文件中执行

const WebSocket = require('ws');

然后运行它:

# nodejs ws.js
internal/modules/cjs/loader.js:583
    throw err;
    ^

Error: Cannot find module 'ws'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at Function.Module._load (internal/modules/cjs/loader.js:507:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (/var/nfs/nodes/api/arbitrage/hotbit.js:1:81)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)

似乎全局模块已安装在/usr/lib/node_modules中,但是除非我手动说出,否则应用程序仍然会失败

export NODE_PATH=/usr/lib/node_modules

这是一个错误吗?

0 个答案:

没有答案