Compatibility with old Node.js broken

cli
triaged

(Martijn) #1

What I Wanted to Do

Update global packages to the latest version using npm -g update while (for legacy reasons I cannot change) on Node 4.3.2.

What Happened Instead

My packages got updated neatly. But NPM updated itself too, and to 6.4.1 at that, which doesn’t work on Node 4.3.2. So NPM will happily update to a version that cannot even work. Which means I have to jump through all kinds of hoops to get back to an earlier version, since I now cannot use NPM to do that, because it doesn’t work…

Reproduction Steps

  1. Install Node.js 4.3.2
  2. Run npm -g update
  3. Try running npm

Details

This is the error you’ll get:

C:\Users\thany>npm
C:\Users\thany\AppData\Roaming\nvm\v4.3.2\node_modules\npm\bin\npm-cli.js:85
      let notifier = require('update-notifier')({pkg})
      ^^^

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:134:18)
    at node.js:962

npm-debug.log does not get created anywhere.

Platform Info

> npm --versions
This spews out the same error as above.

> node -p process.platform
win32

(Lars Willighagen) #2

The engine field on npm’s package.json was removed a long time ago, in

The reason given was that all common node versions were compatible at that point, but they aren’t anymore. Maybe it would be good to add that back for "node": ">=6". This should restrict installing newer versions of npm on older versions of node.


(Kat Marchán) #3

npm@6 dropped support for node@<=4


(Lars Willighagen) #4

Exactly, and the engine field seems to me like a good field to communicate that to older npm versions (PR).