node.js NPM 不再工作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15633029/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 14:00:50  来源:igfitidea点击:

NPM no longer working

javascriptnode.jscommand-linenpmjasmine

提问by praks5432

so I wasn't paying attention and ran this command-

所以我没有注意并运行这个命令 -

npm install npm install jasmine-node -g

which caused this -

这导致了这个 -

    npm http GET https://registry.npmjs.org/install
npm http GET https://registry.npmjs.org/jasmine-node
npm http GET https://registry.npmjs.org/npm
npm http 200 https://registry.npmjs.org/install
npm http GET https://registry.npmjs.org/install/-/install-0.1.7.tgz
npm http 200 https://registry.npmjs.org/install/-/install-0.1.7.tgz
npm http 200 https://registry.npmjs.org/jasmine-node
npm http GET https://registry.npmjs.org/jasmine-node/-/jasmine-node-1.4.0.tgz
npm http 200 https://registry.npmjs.org/jasmine-node/-/jasmine-node-1.4.0.tgz
npm http 200 https://registry.npmjs.org/npm
npm http GET https://registry.npmjs.org/npm/-/npm-1.2.15.tgz
npm http 200 https://registry.npmjs.org/npm/-/npm-1.2.15.tgz
npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/install'
npm ERR!  { [Error: EACCES, mkdir '/usr/local/lib/node_modules/install']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/usr/local/lib/node_modules/install',
npm ERR!   fstream_type: 'Directory',
npm ERR!   fstream_path: '/usr/local/lib/node_modules/install',
npm ERR!   fstream_class: 'DirWriter',
npm ERR!   fstream_stack: 
npm ERR!    [ 'DirWriter._create (/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23)',
npm ERR!      '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53',
npm ERR!      'Object.oncomplete (fs.js:297:15)' ] }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

npm ERR! System Darwin 12.0.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "npm" "install" "jasmine-node" "-g"
npm ERR! cwd /Users/psanker/Google Drive/Coding/Javascript/WhatsGoingOn
npm ERR! node -v v0.8.17
npm ERR! npm -v 1.2.0
npm ERR! path /usr/local/lib/node_modules/install
npm ERR! fstream_path /usr/local/lib/node_modules/install
npm ERR! fstream_type Directory
npm ERR! fstream_class DirWriter
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, mkdir '/usr/local/lib/node_modules/install'
npm ERR! fstream_stack DirWriter._create (/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23)
npm ERR! fstream_stack /usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53
npm ERR! fstream_stack Object.oncomplete (fs.js:297:15)
npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/jasmine-node'
npm ERR!  { [Error: EACCES, mkdir '/usr/local/lib/node_modules/jasmine-node']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/usr/local/lib/node_modules/jasmine-node',
npm ERR!   fstream_type: 'Directory',
npm ERR!   fstream_path: '/usr/local/lib/node_modules/jasmine-node',
npm ERR!   fstream_class: 'DirWriter',
npm ERR!   fstream_stack: 
npm ERR!    [ 'DirWriter._create (/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23)',
npm ERR!      '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53',
npm ERR!      'Object.oncomplete (fs.js:297:15)' ] }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

npm ERR! System Darwin 12.0.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "npm" "install" "jasmine-node" "-g"
npm ERR! cwd /Users/psanker/Google Drive/Coding/Javascript/WhatsGoingOn
npm ERR! node -v v0.8.17
npm ERR! npm -v 1.2.0
npm ERR! path /usr/local/lib/node_modules/jasmine-node
npm ERR! fstream_path /usr/local/lib/node_modules/jasmine-node
npm ERR! fstream_type Directory
npm ERR! fstream_class DirWriter
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, mkdir '/usr/local/lib/node_modules/jasmine-node'
npm ERR! fstream_stack DirWriter._create (/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23)
npm ERR! fstream_stack /usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53
npm ERR! fstream_stack Object.oncomplete (fs.js:297:15)
npm ERR! error rolling back Error: EACCES, unlink '/usr/local/lib/node_modules/npm'
npm ERR! error rolling back  [email protected] { [Error: EACCES, unlink '/usr/local/lib/node_modules/npm']
npm ERR! error rolling back   errno: 3,
npm ERR! error rolling back   code: 'EACCES',
npm ERR! error rolling back   path: '/usr/local/lib/node_modules/npm' }
npm ERR! Error: EACCES, unlink '/usr/local/lib/node_modules/npm'
npm ERR!  { [Error: EACCES, unlink '/usr/local/lib/node_modules/npm']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/usr/local/lib/node_modules/npm' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

npm ERR! System Darwin 12.0.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "npm" "install" "jasmine-node" "-g"
npm ERR! cwd /Users/psanker/Google Drive/Coding/Javascript/WhatsGoingOn
npm ERR! node -v v0.8.17
npm ERR! npm -v 1.2.0
npm ERR! path /usr/local/lib/node_modules/npm
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, unlink '/usr/local/lib/node_modules/npm'
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/psanker/Google Drive/Coding/Javascript/WhatsGoingOn/npm-debug.log
npm ERR! not ok code 0

Now when I try and run

现在当我尝试运行时

npm install jasmine-node -g

I get

我得到

-bash: /usr/local/bin/npm: No such file or directory

What's going on?

这是怎么回事?

采纳答案by asgoth

Tried it myself.

我自己试过了。

You will need to install npmagain. If you use git, this is the easiest way:

您将需要重新安装npm。如果您使用git,这是最简单的方法:

git clone http://github.com/isaacs/npm.git
cd npm
sudo make install

Otherwise, there is an install script too:

否则,也有一个安装脚本:

curl http://npmjs.org/install.sh | sh

(possibly you will need to use sudo shinstead of sh).

(可能您需要使用sudo sh而不是sh)。

Then install your module again:

然后再次安装您的模块:

sudo npm install jasmine-node -g

EDIT 23/01/2014:

编辑 23/01/2014:

Now npm comes with NodeJs itself, so just reinstall NodeJs.

现在 npm 带有 NodeJs 本身,所以只需重新安装NodeJs

回答by Juancarlos Rodríguez

When you run npm install -g somepackage, you may get an EACCES error asking you to run the command again as root/Administrator. It's a permissions issue.

当您运行 npm install -g somepackage 时,您可能会收到 EACCES 错误,要求您以 root/管理员身份再次运行该命令。这是一个权限问题。

It's easy to fix, open your terminal (Applications > Utilities > Terminal)

容易修复,打开你的终端(应用程序 > 实用程序 > 终端)

sudo chown -R $USER /usr/local

** I strongly recommend you to not use the package management with sudo (sudo npm -g install something), because you can get some issues later **

** 我强烈建议你不要在 sudo 中使用包管理(sudo npm -g install something),因为你以后可能会遇到一些问题 **

Reference: http://foohack.com/2010/08/intro-to-npm/

参考:http: //foohack.com/2010/08/intro-to-npm/

** Update **

** 更新 **

The reason is because this can cause permissions problems with lots of other apps, so I'd suggest not doing this.

原因是因为这可能会导致许多其他应用程序出现权限问题,所以我建议不要这样做。

A better solution when you are installing globally:

全局安装时更好的解决方案:

sudo chown -R `whoami` ~/.npm

回答by romainberger

Look at the error

看错误

Please try running this command again as root/Administrator.

You need to run this with sudo

你需要运行这个 sudo

$ sudo npm install jasmine-node -g

回答by Aaron Mcguire

This worked for me (OSX). I had to run it in my user directory.

这对我有用(OSX)。我必须在我的用户目录中运行它。

cd ~

cd ~

curl -L http://npmjs.org/install.sh | sudo sh

curl -L http://npmjs.org/install.sh | sudo sh

回答by Jess

I was able to get around the permissions issues by setting my packages to install locally with a one-line "$HOME/.npmrc" file:

通过将我的软件包设置为使用一行“$HOME/.npmrc”文件在本地安装,我能够解决权限问题:

prefix=${HOME}/.npm_packages

前缀=${HOME}/.npm_packages