nodejs运行项目出现Error: Cannot find module 'ws'错误一般就是缺少了这个为“ws”的module模块,错误信息大致如下:
Error: Cannot find module 'ws' Require stack: - C:\Users\Administrator\Desktop\pcm-player-master\example\server\server.js [90m at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1030:15)[39m [90m at Function.Module._load (internal/modules/cjs/loader.js:899:27)[39m [90m at Module.require (internal/modules/cjs/loader.js:1090:19)[39m [90m at require (internal/modules/cjs/helpers.js:75:18)[39m at Object.<anonymous> (C:\Users\Administrator\Desktop\pcm-player-master\example\server\server.js:1:19) [90m at Module._compile (internal/modules/cjs/loader.js:1201:30)[39m [90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:1221:10)[39m [90m at Module.load (internal/modules/cjs/loader.js:1050:32)[39m [90m at Function.Module._load (internal/modules/cjs/loader.js:938:14)[39m [90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)[39m { code: [32m'MODULE_NOT_FOUND'[39m, requireStack: [ [32m'C:\\Users\\Administrator\\Desktop\\pcm-player-master\\example\\server\\server.js'[39m ] }
这个是websocket模块,我们只需要使用nodejs的npm命令安装这个缺少的“ws”模块即可,例如下面这样:
npm install ws
然后运行我们的项目,就不会有错误信息了。