【问题标题】:Executing .js file on ubuntu 14.04 VPS error在 ubuntu 14.04 VPS 错误上执行 .js 文件
【发布时间】:2023-03-22 10:52:01
【问题描述】:

您好,当我尝试在 ubuntu 上运行我的 sell.js javascript 时出现此错误:

节点卖.js

socket timed out
socket closed
connecting to 72.165.61.175:27018
connected
encrypt request

/var/www/bot/node_modules/steam/lib/steam_client.js:150
  var cryptedSessKey = require('crypto').publicEncrypt(fs.readFileSync(__dirna
                                         ^
TypeError: Object #<Object> has no method 'publicEncrypt'
    at SteamClient.handlers.(anonymous function) (/var/www/bot/node_modules/steam/lib/steam_client.js:150:42)
    at SteamClient._netMsgReceived (/var/www/bot/node_modules/steam/lib/steam_client.js:106:26)
    at Connection.emit (events.js:95:17)
    at Connection._readPacket (/var/www/bot/node_modules/steam/lib/connection.js:50:8)
    at Connection.emit (events.js:92:17)
    at emitReadable_ (_stream_readable.js:427:10)
    at emitReadable (_stream_readable.js:423:5)
    at readableAddChunk (_stream_readable.js:166:9)
    at Connection.Readable.push (_stream_readable.js:128:10)
    at TCP.onread (net.js:529:21)

/var/www/bot/node_modules/steam/lib/steam_client.js 中的代码:

handlers[EMsg.ChannelEncryptRequest] = function(data) {
  this._connection.setTimeout(0);

  this.emit('debug', 'encrypt request');

  this._tempSessionKey = require('crypto').randomBytes(32);
  var cryptedSessKey = require('crypto').publicEncrypt(fs.readFileSync(__dirname + '/public.pub'), this._tempSessionKey);
  var keyCrc = require('buffer-crc32').signed(cryptedSessKey);

  var encResp = new schema.MsgChannelEncryptResponse().encode();
  var body = new ByteBuffer(encResp.limit + 128 + 4 + 4, ByteBuffer.LITTLE_ENDIAN);

  body.append(encResp);
  body.append(cryptedSessKey);
  body.writeInt32(keyCrc);
  body.writeUint32(0);

  this._send(EMsg.ChannelEncryptResponse, body.flip());
};

我做了 npm install --save crypto 但它不起作用我总是收到这个错误。如果有人知道如何解决这个问题,请告诉我。

【问题讨论】:

  • 你已经在 ubuntu 中安装了 build-essentials 吗?一些 NPM 包需要这些来编译依赖。
  • @manuerumx 我安装了它现在尝试再次运行脚本但同样的错误..
  • 您使用的是哪个版本的节点?请注意,如果您从 ubuntu 存储库安装节点,则您拥有旧版本 0.10 或 0.12 这些版本没有 crypto.publicEncrypt 功能。您需要升级到分支 4.x 或 5.x,为此,您需要手动安装 node.js
  • @manuerumx 似乎节点的版本是我遇到的问题 0.10 谢谢你可以回答,我会评价它是正确的

标签: javascript node.js ubuntu


【解决方案1】:

根据反馈和测试,问题是当前 Ubuntu 14.04 存储库有 Node 0.10 分支。在这个分支中,crypto.publicEncrypt API 函数不存在。您必须安装 4.x 或 5.x 版本的 node.js 才能使用这些功能。

https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions

对于 Node.js v4:

curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs

或者,对于 Node.js v5:

curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
sudo apt-get install -y nodejs

可选:安装构建工具

要从 npm 编译和安装本机插件,您可能还需要安装构建工具:

sudo apt-get install -y build-essential

【讨论】:

    猜你喜欢
    • 2015-03-01
    • 1970-01-01
    • 2014-09-11
    • 2014-11-18
    • 2016-06-07
    • 1970-01-01
    • 2017-01-05
    • 1970-01-01
    • 2015-08-03
    相关资源
    最近更新 更多