代码之家  ›  专栏  ›  技术社区  ›  Suresh Prajapati

编译µwebsockets失败,没有预编译的二进制文件

  •  2
  • Suresh Prajapati  · 技术社区  · 7 年前

    我正在尝试使用nodejs和 uws 在Linux机器上。这个 npm install uws 运行时没有任何错误,我可以在我的 node_modules . 但当我尝试使用以下代码创建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 回复  |  直到 6 年前
        1
  •  -1
  •   Suresh Prajapati    7 年前

    安装最新版本 nodejs npm 在Ubuntu和PPA上,解决了这个问题。

    早期版本

    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