none
[Node.js][Web Apps] Buffer.concat is undefined, even though in console it is a function RRS feed

  • Question

  • I'm trying to get a site (http://v1appcatalog-testing.azurewebsites.net/entry) that uses mongodb-core to work, and in the log streaming service I see this error,  about Buffer.concat being undefined:

    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 D:\home\site\wwwroot\node_modules\mongodb\node_modules\mongodb-core\lib\auth\scram.js:79:17

        at D:\home\site\wwwroot\node_modules\mongodb\node_modules\mongodb-core\lib\auth\scram.js:206:30

        at D:\home\site\wwwroot\node_modules\mongodb\node_modules\mongodb-core\lib\topologies\server.js:772:13

        at [object Object].emit (D:\home\site\wwwroot\node_modules\mongodb\node_modules\mongodb-core\lib\topologies\server.js:95:3)

        at [object Object].messageHandler (D:\home\site\wwwroot\node_modules\mongodb\node_modules\mongodb-core\lib\topologies\server.js:243:23)

        at Socket.<anonymous> (D:\home\site\wwwroot\node_modules\mongodb\node_modules\mongodb-core\lib\connection\connection.js:262:22)

        at Socket.emit (events.js:67:17)

        at TCP.onread (net.js:367:14)

        at Socket.<anonymous> (D:\home\site\wwwroot\node_modules\mongodb\node_modules\mongodb-

    core\lib\connection\connection.js:262:22)

    This is similar to what's described here:

    http://stackoverflow.com/questions/26894704/socket-io-error-in-ubuntu-12-04

    The difference is, I am using node version 4, as you can see by the console output:

    > node --version
    D:\home\site\wwwroot
    v4.0.0
    

    And, testing Buffer.concat with a simple script:

    > echo console.log(Buffer.concat) >file.txt
    D:\home\site\wwwroot
    
    > node file.txt
    D:\home\site\wwwroot
    [Function]

    I also tried running npm install manually on the console, and I get this message:

    npm WARN package.json VersionOneAppCatalogService@0.0.2 No repository field.
    
    npm WARN package.json VersionOneAppCatalogService@0.0.2 No license field.
    
    npm WARN peerDependencies The peer dependency kerberos@~0.0 included from mongodb-core will no
    
    npm WARN peerDependencies longer be automatically installed to fulfill the peerDependency 
    
    npm WARN peerDependencies in npm 3+. Your application will need to depend on it explicitly.
    
    gyp WARN install got an error, rolling back install
    
    gyp ERR! configure error 
    
    gyp ERR! stack Error: 404 status code downloading 64-bit node.lib
    
    gyp ERR! stack     at Request.<anonymous> (c:\Program Files (x86)\npm\2.14.2\node_modules\npm\node_modules\node-gyp\lib\install.js:403:20)
    
    gyp ERR! stack     at emitOne (events.js:82:20)
    
    gyp ERR! stack     at Request.emit (events.js:169:7)
    
    gyp ERR! stack     at Request.onRequestResponse (c:\Program Files (x86)\npm\2.14.2\node_modules\npm\node_modules\request\request.js:1008:10)
    
    gyp ERR! stack     at emitOne (events.js:77:13)
    
    gyp ERR! stack     at ClientRequest.emit (events.js:169:7)
    
    gyp ERR! stack     at HTTPParser.parserOnIncomingClient (_http_client.js:415:21)
    
    gyp ERR! stack     at HTTPParser.parserOnHeadersComplete (_http_common.js:88:23)
    
    gyp ERR! stack     at TLSSocket.socketOnData (_http_client.js:305:20)
    
    gyp ERR! stack     at emitOne (events.js:77:13)
    
    gyp ERR! System Windows_NT 6.2.9200
    
    gyp ERR! command "D:\\Program Files (x86)\\nodejs\\4.0.0\\node.exe" "c:\\Program Files (x86)\\npm\\2.14.2\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
    

    Anyone have any ideas on what is going on here?

    Thanks,

    Josh



    Tuesday, November 10, 2015 8:21 PM

Answers

  • Holy cow..I think this was the solution:

    https://github.com/versionone/VersionOne.AppCatalog.Web/commit/8346aea16e22ff99c75061ae025427097ed62ba8

    Even though the Deployment Log showed 4.0.0 because of the App Settings, the iisnode element was overriding that!!!

    <iisnode 
         nodeProcessCommandLine="&quot;%programfiles(x86)%\nodejs\node.exe&quot;"

    I just made it nodejs\4.0.0 and it worked!

    http://v1appcatalog-testing.azurewebsites.net/entry

    I don't think we actually need this nodeProcessCommandLine anymore. It has been there for years, and I think it might be outdated.


    Thursday, November 12, 2015 8:51 PM

All replies

  • I also noticed this:

    gyp ERR! stack Error: 404 status code downloading 64-bit node.lib

    More context:

    > npm install --save kerberos
    D:\home\site\wwwroot
    npm WARN package.json VersionOneAppCatalogService@0.0.2 No repository field.
    
    npm WARN package.json VersionOneAppCatalogService@0.0.2 No license field.
    
    gyp WARN install got an error, rolling back install
    
    gyp ERR! configure error 
    
    gyp ERR! stack Error: 404 status code downloading 64-bit node.lib
    
    gyp ERR! stack     at Request.<anonymous> (c:\Program Files (x86)\npm\2.14.2\node_modules\npm\node_modules\node-gyp\lib\install.js:403:20)
    
    gyp ERR! stack     at emitOne (events.js:82:20)
    
    gyp ERR! stack     at Request.emit (events.js:169:7)
    
    gyp ERR! stack     at Request.onRequestResponse (c:\Program Files (x86)\npm\2.14.2\node_modules\npm\node_modules\request\request.js:1008:10)
    
    gyp ERR! stack     at emitOne (events.js:77:13)
    
    gyp ERR! stack     at ClientRequest.emit (events.js:169:7)
    
    gyp ERR! stack     at HTTPParser.parserOnIncomingClient (_http_client.js:415:21)
    
    gyp ERR! stack     at HTTPParser.parserOnHeadersComplete (_http_common.js:88:23)
    
    gyp ERR! stack     at TLSSocket.socketOnData (_http_client.js:305:20)
    
    gyp ERR! stack     at emitOne (events.js:77:13)
    
    gyp ERR! System Windows_NT 6.2.9200
    
    gyp ERR! command "D:\\Program Files (x86)\\nodejs\\4.0.0\\node.exe" "c:\\Program Files (x86)\\npm\\2.14.2\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
    
    gyp ERR! cwd D:\home\site\wwwroot\node_modules\kerberos
    
    gyp ERR! node -v v4.0.0
    
    gyp ERR! node-gyp -v v2.0.2
    
    gyp ERR! not ok 
    

    Tuesday, November 10, 2015 8:34 PM
  • Hi,

    It seems that you failed to install Kerberos, I would suggest you have a look at this article: https://www.npmjs.com/package/kerberos, hope it helps, if not, please feel free come back.

    Best Regards,

    Jambor 


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, November 11, 2015 9:35 AM
    Moderator
  • Hi Jamboor,

    Thanks for your response. I've been trying everything. I compiled Kerberos locally and made sure all the binaries were included in my repo, and redeployed the site.

    I do not think the issue has to do with Kerberos, at least not at the moment, because I'm still getting the Buffer.concat issue, which is very unexpected because I'm running under Node v4.0.0 and I can reference Buffer.concat from the Kudu Console, for example:

    D:\home>node --version
    v4.0.0

    D:\home>node -e "console.log(Buffer.concat)"
    [Function]

    It still produces this error:

      SlowBuffer.makeFastBuffer(this.parent, this, this.offset, this.length);

    } has no method 'concat'
        at D:\home\site\wwwroot\node_modules\mongodb\node_modules\mongodb-core\lib\auth\scram.js:79:17
        at D:\home\site\wwwroot\node_modules\mongodb\node_modules\mongodb-core\lib\auth\scram.js:206:30

    When I look at line 79 of scram.js, it is Buffer.concat:

    https://github.com/christkv/mongodb-core/blob/master/lib/auth/scram.js#L79

      // Create variables
      salt = Buffer.concat([salt, new Buffer('\x00\x00\x00\x01')])
      var ui = digest(salt);
      var u1 = ui;

    I'm very perplexed by this, and don't have any idea what to try next, short of producing my own forked module and manually pulling in the old-school:

    https://www.npmjs.com/package/buffer-concat

    It specifically says this is "concat patch for Buffer in node < 0.8.", 

    Here's something else....

    In  KUDU I can see that both nodejs and nodejs4 are part of the path:

    PATH =
    D:\Program Files (x86)\Mercurial\
    d:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\
    D:\Program Files (x86)\nodejs\
    D:\Program Files (x86)\nodejs\4.0.0
    D:\Program Files (x86)\PHP\v5.4
    D:\Python27
    D:\Users\Administrator\AppData\Roaming\npm
    D:\Windows
    D:\Windows\system32
    D:\Windows\System32\Wbem
    D:\Windows\System32\WindowsPowerShell\v1.0\

    When I go to that first folder, I see it is v0.6.20, obviously < 0.8.0

    d:\>cd "Program Files (x86)"

    d:\Program Files (x86)>cd nodejs

    d:\Program Files (x86)\nodejs>node --version
    v0.6.20

    However, looking at the bigger output of Environment Variables, the 4.0 comes before the root one, so maybe it's getting overridden?

    • Path = D:\Program Files (x86)\nodejs\4.0.0;D:\Windows\system32;D:\Windows;D:\Windows\System32\Wbem;D:\Windows\System32\WindowsPowerShell\v1.0\;D:\Users\Administrator\AppData\Roaming\npm;D:\Program Files (x86)\nodejs\;d:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;D:\Program Files (x86)\Mercurial\;D:\Program Files (x86)\PHP\v5.4;D:\Python27;


    In any case, I really can't understand why this line of code is failing, since the site is supposed to be running under Version 4.0.0.

    Thanks!

    Josh



    • Edited by JoshuaGough Thursday, November 12, 2015 8:36 PM
    Thursday, November 12, 2015 8:28 PM
  • Holy cow..I think this was the solution:

    https://github.com/versionone/VersionOne.AppCatalog.Web/commit/8346aea16e22ff99c75061ae025427097ed62ba8

    Even though the Deployment Log showed 4.0.0 because of the App Settings, the iisnode element was overriding that!!!

    <iisnode 
         nodeProcessCommandLine="&quot;%programfiles(x86)%\nodejs\node.exe&quot;"

    I just made it nodejs\4.0.0 and it worked!

    http://v1appcatalog-testing.azurewebsites.net/entry

    I don't think we actually need this nodeProcessCommandLine anymore. It has been there for years, and I think it might be outdated.


    Thursday, November 12, 2015 8:51 PM