Unable to install/ uninstall anything using npm

2019-08-28 23:50发布

问题:

I'm working through a tutorial about learning npm, but am having trouble with even the simplest instructions.

Basically the first instruction given was to install the node-dev package globally, using the Terminal line: sudo npm install -g node-dev. Unfortunately, this spits out an error:

npm ERR! code MODULE_NOT_FOUND
npm ERR! Cannot find module './access-error.js'

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/samlegros/.npm/_logs/2019-02-26T00_36_39_572Z-debug.log

After some Googling and digging, nothing seemed to work for my case. So I thought I would try fully removing and reinstalling npm to start with a clean slate (I had worked with npm a while back, so maybe something messed up back then).

Even going through the official npm-removal documentation, I still get a similar error! I can't even remove npm properly...

npm ERR! code MODULE_NOT_FOUND
npm ERR! Cannot find module './access-error.js'

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/samlegros/.npm/_logs/2019-02-26T00_38_40_865Z-debug.log

Any help would be deeply appreciated. I've tried several npm tutorials over the months and they always result in errors that I just never know how to overcome, very discouraging :(

(error log, if that helps)

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node',
1 verbose cli   '/usr/local/bin/npm',
1 verbose cli   'uninstall',
1 verbose cli   'npm',
1 verbose cli   '-g' ]
2 info using npm@6.8.0
3 info using node@v8.11.1
4 verbose stack Error: Cannot find module './access-error.js'
4 verbose stack     at Function.Module._resolveFilename (module.js:547:15)
4 verbose stack     at Function.Module._load (module.js:474:25)
4 verbose stack     at Module.require (module.js:596:17)
4 verbose stack     at require (internal/module.js:11:18)
4 verbose stack     at Object.<anonymous> (/usr/local/lib/node_modules/npm/lib/install/exists.js:4:19)
4 verbose stack     at Module._compile (module.js:652:30)
4 verbose stack     at Object.Module._extensions..js (module.js:663:10)
4 verbose stack     at Module.load (module.js:565:32)
4 verbose stack     at tryModuleLoad (module.js:505:12)
4 verbose stack     at Function.Module._load (module.js:497:3)
4 verbose stack     at Module.require (module.js:596:17)
4 verbose stack     at require (internal/module.js:11:18)
4 verbose stack     at Object.<anonymous> (/usr/local/lib/node_modules/npm/lib/install/check-permissions.js:8:14)
4 verbose stack     at Module._compile (module.js:652:30)
4 verbose stack     at Object.Module._extensions..js (module.js:663:10)
4 verbose stack     at Module.load (module.js:565:32)
5 verbose cwd /path/to/tutorial/
6 verbose Darwin 18.2.0
7 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "uninstall" "npm" "-g"
8 verbose node v8.11.1
9 verbose npm  v6.8.0
10 error code MODULE_NOT_FOUND
11 error Cannot find module './access-error.js'
12 verbose exit [ 1, true ]

回答1:

I simply removed Node.js from my Mac and reinstalled it, that worked.

Command used to remove Node.js: sudo rm -rf /usr/local/{bin/{node,npm},lib/node_modules/npm,lib/node,share/man/*/node.*}

Everything works great now.



标签: node.js npm