简体   繁体   中英

npm install error - SyntaxError: Block-scoped declarations

Im trying to install create-react-app but it throws me this error -

rem$ npm install -g create-react-app
Command failed: /bin/sh -c /usr/local/bin/node /usr/local/lib/node_modules/npm/bin/npm-cli.js config get cache --parseable
/usr/local/lib/node_modules/npm/bin/npm-cli.js:82
      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:414:25)
    at Object.Module._extensions..js (module.js:442:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Function.Module.runMain (module.js:467:10)
    at startup (node.js:136:18)
    at node.js:963:3

I updated both npm and node but still get the same problem.

brew upgrade npm brew upgrade node

rem$ brew upgrade npm
Error: npm 10.9.0 already installed
rem$ brew upgrade node
Error: node 10.9.0 already installed

I had similar trouble with npm. Although I had node 10, it was still defaulting to node@4. Then I installed nvm and used it install specific nodejs version and use it. On Mac,

curl https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash

export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" 
nvm install <specify nodejs version you require>
nvm use <specify version of nodejs> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM