µWebSockets的编译失败,并且没有预编译的二进制文件

时间:2018-07-15 09:44:37

标签: node.js npm websocket uwebsockets

我正在尝试在Linux机器上使用nodejs和uws运行本地websocket服务器。 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,发现本机函数由于缺少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

提前致谢

1 个答案:

答案 0 :(得分:-1)

在具有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