Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
241 views
in Technique[技术] by (71.8m points)

node.js - npm update broke npm

I just followed this guide to update npm (as my nodered camera module wasn't working) and ran

npm install -g npm

but now my npm install seems completely broken. If I just type

npm

or

npm update

I get

/usr/local/lib/node_modules/npm/bin/npm-cli.js:79 let notifier = require('update-notifier')({pkg}) ^^^

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode

I've tried

sudo apt-get remove npm
sudo apt-get install npm

but the reinstall didn't help.

I think my node version needs upgrading from v4.8.2 but I thought that was only possible with npm?

question from:https://stackoverflow.com/questions/50316693/npm-update-broke-npm

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You probably have npm installed twice, one is in /usr/local/bin and the other in /usr/bin.

First, you can try to remove the npm module that has been installed by upgrading npm. Try to run this:

  • rm -r /usr/local/lib/node_modules/npm
  • /usr/bin/npm uninstall npm

Once you have a running version of npm, install a more recent version of node before upgrading npm. Then, remove the version of your linux distribution.

If the first solution doesn't work, another approach is to install a recent version of node (without using npm of course):

curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y nodejs

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...