NPM不再工作

NPM no longer working

本文关键字:工作 不再 NPM      更新时间:2023-09-26

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

npm install npm install jasmine-node -g

导致这个-

    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  npm@1.2.15 { [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

现在当我试着运行

npm install jasmine-node -g

我得到

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

怎么回事?

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

很容易修复,打开你的终端(应用程序>工具>终端)
sudo chown -R $USER /usr/local

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

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

** Update **

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

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

sudo chown -R `whoami` ~/.npm

我自己试过了。

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

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

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

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

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

然后重新安装你的模块:

sudo npm install jasmine-node -g

编辑23/01/2014:

现在npm自带NodeJs,所以只要重新安装NodeJs。

查看错误

Please try running this command again as root/Administrator.

您需要使用sudo

运行此命令
$ sudo npm install jasmine-node -g

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

cd ~

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

我可以通过一行"$HOME/"将我的包设置为本地安装来解决权限问题。npmrc"文件:

前缀= ${回家}/.npm_packages