How can I update NodeJS and NPM to the next versions?

后端 未结 30 1658
北荒
北荒 2020-11-22 08:07

I just installed Node.js and npm (for additional modules).

How can I update Node.js and the modules which I\'m using to the latest versions

30条回答
  •  伪装坚强ぢ
    2020-11-22 08:52

    Warning: if you need update Node from an old version (in my case v4.6.0) it is better to re-install nodejs from scratch (download link: https://nodejs.org) otherwise npm will also update itself to a version that's not compatible with the new Node (see this discussion).

    This is the error message that I got after updating Node (on Windows) with npm

    $ npm install -g npm stable
    [ . . .]
    $ npm 
    C:\Users\me\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js:85
          let notifier = require('update-notifier')({pkg})
          ^^^
    
    SyntaxError: Block-scoped declarations (let, const, function, class) not yet supporte
    d 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:139:18)
        at node.js:974:3
    

    After new installation npm works again:

    $ npm -v
    6.5.0
    $ node -v
    v10.15.0
    

提交回复
热议问题