【问题标题】:Socket.io error in Ubuntu 12.04Ubuntu 12.04 中的 Socket.io 错误
【发布时间】:2015-01-09 18:16:38
【问题描述】:

我刚刚将 node.js、npm 和 mongodb 安装到了新的 Ubuntu 12.04 服务器上。当我尝试打开我的网站时,我收到了这个错误:

/home/proj/node_modules/socket.io/node_modules/engine.io/node_modules/engine.io-parser/lib/index.js:402
        return doneCallback(null, Buffer.concat([sizeBuffer, stringToBuffer(pa
                                         ^
TypeError: Object function Buffer(subject, encoding, offset) {
  if (!(this instanceof Buffer)) {
    return new Buffer(subject, encoding, offset);
  }

  var type;

  // Are we slicing?
  if (typeof offset === 'number') {
    this.length = coerce(encoding);
    this.parent = subject;
    this.offset = offset;
  } else {
    // Find the length
    switch (type = typeof subject) {
      case 'number':
        this.length = coerce(subject);
        break;

      case 'string':
        this.length = Buffer.byteLength(subject, encoding);
        break;

      case 'object': // Assume object is an array
        this.length = coerce(subject.length);
        break;

      default:
        throw new Error('First argument needs to be a number, ' +
                        'array or string.');
    }

    if (this.length > Buffer.poolSize) {
      // Big buffer, just alloc one.
      this.parent = new SlowBuffer(this.length);
      this.offset = 0;

    } else {
      // Small buffer.
      if (!pool || pool.length - pool.used < this.length) allocPool();
      this.parent = pool;
      this.offset = pool.used;
      pool.used += this.length;
    }

    // Treat array-ish objects as a byte array.
    if (isArrayIsh(subject)) {
      for (var i = 0; i < this.length; i++) {
        this.parent[i + this.offset] = subject[i];
      }
    } else if (type == 'string') {
      // We are a string
      this.length = this.write(subject, 0, encoding);
    }
  }

  SlowBuffer.makeFastBuffer(this.parent, this, this.offset, this.length);
} has no method 'concat'
    at /home/proj/node_modules/socket.io/node_modules/engine.io/node_modules/engine.io-parser/lib/index.js:402:42

这可能是什么原因?在 localhost 中一切正常。

【问题讨论】:

    标签: node.js mongodb socket.io ubuntu-12.04


    【解决方案1】:

    Buffer.concat 仅在 Node 0.8 中受支持。您需要将 Node 升级到最新版本。 Ubuntu 12.04 只提供 Node 0.6

    要升级,可以运行以下命令

    $ npm install -g n
    $ n stable
    

    这会将最新的节点安装到 /usr/local/bin。

    您可以使用运行您的节点应用程序

    $ /usr/local/bin/node path-to-your-node-app
    

    https://github.com/tj/n阅读更多关于节点二进制管理的信息,它可以帮助您管理多节点二进制安装。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-06
      • 1970-01-01
      • 2013-06-26
      • 2012-12-12
      • 2013-08-08
      • 2017-10-18
      • 2013-01-17
      • 2015-06-01
      相关资源
      最近更新 更多