Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

NPM 5.4.0 errors on NodeJS 4.2.6 #18395

Closed
1 of 13 tasks
nicwortel opened this issue Sep 4, 2017 · 16 comments
Closed
1 of 13 tasks

NPM 5.4.0 errors on NodeJS 4.2.6 #18395

nicwortel opened this issue Sep 4, 2017 · 16 comments

Comments

@nicwortel
Copy link

nicwortel commented Sep 4, 2017

I'm opening this issue because:

  • npm is crashing.
  • npm is producing an incorrect install.
  • npm is doing something I don't understand.
  • Other (see below for feature requests):

What's going wrong?

npm install shows:

npm ERR! Buffer.alloc is not a function

npm ERR! A complete log of this run can be found in:
npm ERR! /home/nic/.npm/_logs/2017-09-04T13_49_57_682Z-debug.log

npm-debug.log contents:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/nodejs', '/usr/local/bin/npm', 'install' ]
2 info using npm@5.4.0
3 info using node@v4.2.6
4 verbose stack TypeError: Buffer.alloc is not a function
4 verbose stack at Object. (/usr/local/lib/node_modules/npm/node_modules/tar/lib/pack.js:32:20)
4 verbose stack at Module._compile (module.js:410:26)
4 verbose stack at Object.Module._extensions..js (module.js:417:10)
4 verbose stack at Module.load (module.js:344:32)
4 verbose stack at Function.Module._load (module.js:301:12)
4 verbose stack at Module.require (module.js:354:17)
4 verbose stack at require (internal/module.js:12:17)
4 verbose stack at Object. (/usr/local/lib/node_modules/npm/node_modules/tar/lib/create.js:6:14)
4 verbose stack at Module._compile (module.js:410:26)
4 verbose stack at Object.Module._extensions..js (module.js:417:10)
4 verbose stack at Module.load (module.js:344:32)
4 verbose stack at Function.Module._load (module.js:301:12)
4 verbose stack at Module.require (module.js:354:17)
4 verbose stack at require (internal/module.js:12:17)
4 verbose stack at Object. (/usr/local/lib/node_modules/npm/node_modules/tar/index.js:4:30)
4 verbose stack at Module._compile (module.js:410:26)
5 verbose cwd /home/nic/projects/[redacted]
6 verbose Linux 4.10.0-33-generic
7 verbose argv "/usr/bin/nodejs" "/usr/local/bin/npm" "install"
8 verbose node v4.2.6
9 verbose npm v5.4.0
10 error Buffer.alloc is not a function
11 verbose exit [ 1, true ]

How can the CLI team reproduce the problem?

Run npm install on NPM v5.4.0 on NodeJS v4.2.6 (the default version in the Ubuntu repositories).

supporting information:

  • npm -v prints: 5.4.0
  • node -v prints: v4.2.6
  • npm config get registry prints: https://registry.npmjs.org/
  • Windows, OS X/macOS, or Linux?: Linux (Ubuntu 16.04.3 LTS)
  • Network issues:
    • Geographic location where npm was run: The Netherlands
    • I use a proxy to connect to the npm registry.
    • I use a proxy to connect to the web.
    • I use a proxy when downloading Git repos.
    • I access the npm registry via a VPN
    • I don't use a proxy, but have limited or unreliable internet access.
  • Container:
    • I develop using Vagrant on Windows.
    • I develop using Vagrant on OS X or Linux.
    • I develop / deploy using Docker.
    • I deploy to a PaaS (Triton, Heroku).
@nicwortel
Copy link
Author

nicwortel commented Sep 4, 2017

A google search suggests that the Buffer.alloc API was introduced in a later version of NodeJS (4.5.0). However the readme suggests that NPM 5.4.0 should work with NodeJS 4 or higher:

You need node v4 or higher to run this program.

Therefor I believe this is a regression (everything worked fine in v5.3.0) and/or a case of outdated documentation.

@nicwortel nicwortel changed the title Update the minimum NodeJS requirement NPM 5.4.0 errors on NodeJS 4.2.6 Sep 4, 2017
@kenany
Copy link
Contributor

kenany commented Sep 4, 2017

Hmm, yeah, looks like tar@4 (added in npm@5.4.0) requires Node.js >=4.5, so you're right 👍

@nicwortel
Copy link
Author

nicwortel commented Sep 4, 2017

Ah, I see.

What I don't understand is the package.json of tar contains the Node.js >=4.5 requirement:

"engines": {
    "node": ">=4.5"
}

But NPM doesn't warn me about this when I upgrade NPM to version 5.4.0 (using sudo npm install npm@latest -g on Node.js v4.2.6). I only get the following output:

/usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js
/usr/local/bin/npx -> /usr/local/lib/node_modules/npm/bin/npx-cli.js

  • npm@5.4.0
    added 22 packages, removed 22 packages and updated 19 packages in 5.862s

Does NPM only warn about engine requirements of the package you're installing, not of its dependencies?

@kenany
Copy link
Contributor

kenany commented Sep 4, 2017

@nicwortel Hmm, how about?:

npm install npm@latest -g --loglevel warn

@goneglobal
Copy link

I experienced the same issue today (on Ubuntu 16.04)

I managed to fix it (hope this helps you too) by doing the following:

Update nodejs to latest version:
Get the repo's

cd ~
curl -sL https://deb.nodesource.com/setup_6.x -o nodesource_setup.sh

Install latest version of nodejs via apt get

sudo apt-get install nodejs

Result

adam@adam-pc:/~$ nodejs --version
v6.11.2
adam@adam-pc:/~$ npm --version
5.4.0

NPM now works!

sudo npm install react-router -g
npm WARN react-router@4.2.0 requires a peer of react@>=15 but none is installed. You must install peer dependencies yourself.

+ react-router@4.2.0
added 25 packages in 1.978s

NO MORE OF THIS!!

npm ERR! Buffer.alloc is not a function

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/adam/.npm/_logs/2017-09-05T01_54_26_473Z-debug.log

@nicwortel
Copy link
Author

@kenany yes I did see the warning with the --loglevel warn. But I think this warning should be shown by default. I also enabled the 'engine-strict' setting.

In the meantime I fixed the issue by upgrading NPM to a newer version, as per @goneglobal's suggestion.

@kenany
Copy link
Contributor

kenany commented Sep 5, 2017

@nicwortel All right. Just curious, what's the output of npm config get loglevel?

puxlit added a commit to puxlit/XKit that referenced this issue Sep 6, 2017
This is a stopgap for build failures described in npm/npm#18395.
invalidCards pushed a commit to new-xkit/XKit that referenced this issue Sep 6, 2017
This is a stopgap for build failures described in npm/npm#18395.
@andilabs
Copy link

andilabs commented Sep 7, 2017

@goneglobal how did you installed nodejs in version v6.11.2? I am still getting 4.2.6 following your steps... but this instructions with using NVM seems working https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-16-04

@nicwortel
Copy link
Author

@nicwortel All right. Just curious, what's the output of npm config get loglevel?

It's notice. I don't believe I've ever changed that piece of configuration (and the same issue also occurred on fresh Vagrant boxes).

@sleekweasel
Copy link
Contributor

I observe this behaviour with node 4.5.1 and npm 4.5.1, so unless my set-up is especially strange (there's scope in the stacktrace for mixed versions, given that only some of the lines have an absolute path) there's a flaw there too:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'install' ]
2 info using npm@5.4.1
3 info using node@v5.4.1
4 verbose stack TypeError: Buffer.alloc is not a function
4 verbose stack at Object. (/usr/lib/node_modules/npm/node_modules/tar/lib/pack.js:32:20)
4 verbose stack at Module._compile (module.js:397:26)
4 verbose stack at Object.Module._extensions..js (module.js:404:10)
4 verbose stack at Module.load (module.js:343:32)
4 verbose stack at Function.Module._load (module.js:300:12)
4 verbose stack at Module.require (module.js:353:17)
4 verbose stack at require (internal/module.js:12:17)
4 verbose stack at Object. (/usr/lib/node_modules/npm/node_modules/tar/lib/create.js:6:14)
4 verbose stack at Module._compile (module.js:397:26)
4 verbose stack at Object.Module._extensions..js (module.js:404:10)
4 verbose stack at Module.load (module.js:343:32)
4 verbose stack at Function.Module._load (module.js:300:12)
4 verbose stack at Module.require (module.js:353:17)
4 verbose stack at require (internal/module.js:12:17)
4 verbose stack at Object. (/usr/lib/node_modules/npm/node_modules/tar/index.js:4:30)
4 verbose stack at Module._compile (module.js:397:26)
5 verbose cwd /local/buildAgent/work/376a8546dc012366/bumble
6 verbose Linux 4.10.0-28-generic
7 verbose argv "/usr/bin/node" "/usr/bin/npm" "install"
8 verbose node v5.4.1
9 verbose npm v5.4.1
10 error Buffer.alloc is not a function
11 verbose exit [ 1, true ]

@iarna
Copy link
Contributor

iarna commented Sep 10, 2017

npm supports the latest Node.js v4, which is v4.8.4.

@thetrompf
Copy link

thetrompf commented Sep 10, 2017

@iarna I think the readme should be a bit more explicit about this requirement, right now it says:

You need node v4 or higher to run this program.

Which does not cover it has to be the latest v4, also due to LTS vs. non-LTS support periods node v5 is not supported, even though it fits node v4 or higher.

@iarna
Copy link
Contributor

iarna commented Sep 10, 2017

We officially support the latest version of Node.js in all of it's LTS branches. (We don't have the resources to work around every bug in every point release of node any more than the Node.js project does. There are 72 of those currently, for reference.)

Now, I wouldn't be opposed to patching safe-buffer, the Buffer.alloc pollyfill, in everywhere to get compatibility with older v4s and in fact I just went and tried to do this…

But it turns out that it isn't enough. Indeed, npm doesn't run under the first releases of Node v4 that introduce Buffer.alloc and this is due to along standing bug in the Node.js zlib implementation.

This bug was fixed in 4.7.0 and as such that's the minimum version that works with npm.

I will be introducing new unsupported version messaging that will hopefully be more helpful than what we've had previously. The way that works is if you try to run npm under an older version of npm@4 you'll get:

ERROR: npm is known not to run on Node.js v4.6.2
Node.js 4 is supported but the specific version you're running has
a bug known to break npm. Please update to at least 4.7.0 to use this
version of npm. You can find the latest release of Node.js at https://nodejs.org/

I'll also write up a clarifying blog post discussing what versions of Node.js we support.

As I don't think there's anything further we can do on this issue I'm going to close it, but please feel free to reach out if you think further discussion is warrented.

@iarna iarna closed this as completed Sep 10, 2017
@ColaKaii
Copy link

I try to upgrade nodejs over 4.7.0 in ubuntu,
but it came out this.

How could I upgrade nodejs ?

$ sudo apt-get install nodejs

Reading package lists... Done
Building dependency tree
Reading state information... Done
nodejs is already the newest version (4.2.6~dfsg-1ubuntu4.1).
0 upgraded, 0 newly installed, 0 to remove and 38 not upgraded.

@thetrompf
Copy link

thetrompf commented Sep 12, 2017

The following should do the trick:

  • v4.8.7:
(cd /usr/local && sudo wget -O- https://nodejs.org/dist/v4.8.4/node-v4.8.4-linux-x64.tar.gz | sudo tar --strip-components=1 -xzf -)
  • v4.7.0:
(cd /usr/local && sudo wget -O- https://nodejs.org/dist/v4.7.0/node-v4.7.0-linux-x64.tar.gz | sudo tar --strip-components=1 -xzf -)

v4.8.4 is the latest version of node v4.

Remember to uninstall nodejs first.

sudo apt-get remove nodejs

@soundarsurya
Copy link

i have did all the methods above but i cant update the version from v4.2.6
even i uninstall all packages and re install it

help me to fix

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants