gpt4 book ai didi

javascript - Node.js - 找不到模块 'websocket'

转载 作者:行者123 更新时间:2023-11-30 14:57:34 25 4
gpt4 key购买 nike

我是 node.js 的新手,我需要使用模块 websocket。我的服务器:

$ cat /etc/centos-release
CentOS Linux release 7.2.1511 (Core)

$ node --version
v6.11.5

$ npm --version
3.10.10

使用 $ npm install websocket 安装了一个模块,但是当我尝试我的文件时,它给了我这个:

$ node /var/www/js/test.js
module.js:471
throw err;
^

Error: Cannot find module 'websocket'

这是我的 JS 文件的第一行:

var WebSocketClient = require('websocket').client;

我还尝试了以下命令:

$ npm install websocket (with and without -g flag)
$ npm link websocket
$ npm install -d

但没有任何帮助。

package.json:

{
"name": "root",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"websocket": "^1.0.25"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}

最佳答案

你必须在你的文件中尝试这个 var websocket = require('websocket');

关于javascript - Node.js - 找不到模块 'websocket',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47012750/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com