gpt4 book ai didi

node.js - µWebSockets 编译失败且没有预编译二进制文件

转载 作者:太空宇宙 更新时间:2023-11-03 22:39:48 26 4
gpt4 key购买 nike

我正在尝试使用nodejs和uws运行本地websocket服务器在 Linux 机器上。 npm install uws 运行时没有任何错误,我可以在 node_modules 中看到一个名为 uws 的文件夹。但是当我尝试使用以下代码创建 websocket 服务器时。它给了我错误

/home/suresh/browserstack/node_modules/uws/uws.js:40
throw new Error('Compilation of µWebSockets has failed and there is no pre-compiled binary ' +
^

Error: Compilation of µWebSockets has failed and there is no pre-compiled binary available for your system. Please install a supported C++11 compiler and reinstall the module 'uws'.
at e (/home/suresh/browserstack/node_modules/uws/uws.js:40:19)
at Object.<anonymous> (/home/suresh/browserstack/node_modules/uws/uws.js:44:3)
at Module._compile (module.js:577:32)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/home/suresh/browserstack/ws/index.js:1:95)

这是我的js代码:

const WebSocket = require('uws').Server;
var http = require('http');

var server = http.createServer(function(request, response) {});

var wss = new WebSocket({
server: server,
path: '/wss'
});

var connCounter = 1;
wss.on('connection', function(ws){
console.log('new connection');

ws.id = connCounter;
ws.on('message', function(message){

});

ws.on('close', clearWS);
ws.on('end', clearWS);
ws.on('disconnect', clearWS);
ws.on('error', clearWS);

function clearWS(e){
console.log('in clearWS', e);
}
})

function sendBuffer(ws, buffer){
if (ws && ws.readyState == 1)
ws.send(buffer);
}

我查看了 /home/suresh/browserstack/node_modules/uws/uws.js:40 并发现 native 函数由于缺少 uws_linux_48 文件而失败。以下是添加的打印错误日志语句:

Error: Cannot find module './uws_linux_48'
at Function.Module._resolveFilename (module.js:476:15)
at Function.Module._load (module.js:424:25)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at e (/home/suresh/browserstack/node_modules/uws/uws.js:29:20)
at Object.<anonymous> (/home/suresh/browserstack/node_modules/uws/uws.js:45:3)
at Module._compile (module.js:577:32)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12) code: 'MODULE_NOT_FOUND' }

我在互联网上搜索并发现了一些 github 问题和评论,但没有帮助。

这是我的系统信息:

gcc - version 5.5.0
node - v6.14.3
npm - 3.10.10

提前致谢

最佳答案

使用 PPA 在 Ubuntu 上安装最新的 nodejsnpm,解决了这个问题。

早期版本

node - v6.14.3
npm - 3.10.10

最新版本解决了问题-

node - v10.6.0
npm - 6.1.0

引用 - How to Install Latest Node.js and NPM on Ubuntu with PPA

关于node.js - µWebSockets 编译失败且没有预编译二进制文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51347190/

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