npm安装任何包都无效

➜  bin vi npm
➜  bin npm install npm@latest -g
npm ERR! Darwin 15.2.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "npm@latest" "-g"
npm ERR! node v6.8.0
npm ERR! npm  v3.10.8
npm ERR! code MODULE_NOT_FOUND

npm ERR! Cannot find module 'realize-package-specifier'
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR!     /usr/local/bin/npm-debug.log
➜  bin npm -v
3.10.8
➜  bin node -v
v6.8.0
➜  bin

npm安装任何依赖包都无效,但是npm和node确实都是OK的。换了国内的淘宝镜像也无效。

上传不了图片,贴下代码。

今天5月18日重新安装了node和npm,通过pkg安装包安装的,依然报错。真是日了狗了

WARN EACCES user "root" does not have permission to access the dev dir "/usr/local/lib/node_modules/mip-cli/node_modules/utf-8-validate/.node-gyp/8.11.2"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/mip-cli/node_modules/utf-8-validate/.node-gyp"
gyp WARN EACCES user "root" does not have permission to access the dev dir "/usr/local/lib/node_modules/mip-cli/node_modules/utf-8-validate/.node-gyp/8.11.2"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/mip-cli/node_modules/utf-8-validate/.node-gyp"
gyp WARN EACCES user "root" does not have permission to access the dev dir "/usr/local/lib/node_modules/mip-cli/node_modules/utf-8-validate/.node-gyp/8.11.2"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/mip-cli/node_modules/utf-8-validate/.node-gyp"
gyp WARN EACCES user "root" does not have permission to access the dev dir "/usr/local/lib/node_modules/mip-cli/node_modules/utf-8-validate/.node-gyp/8.11.2"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/mip-cli/node_modules/utf-8-validate/.node-gyp"
gyp WARN EACCES user "root" does not have permission to access the dev dir "/usr/local/lib/node_modules/mip-cli/node_modules/utf-8-validate/.node-gyp/8.11.2"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/mip-cli/node_modules/utf-8-validate/.node-gyp"
gyp WARN EACCES user "root" does not have permission to access the dev dir "/usr/local/lib/node_modules/mip-cli/node_modules/utf-8-validate/.node-gyp/8.11.2"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/mip-cli/node_modules/utf-8-validate/.node-gyp"
gyp WARN EACCES user "root" does not have permission to access the dev dir "/usr/local/lib/node_modules/mip-cli/node_modules/utf-8-validate/.node-gyp/8.11.2"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/mip-cli/node_modules/utf-8-validate/.node-gyp"
gyp WARN EACCES user "root" does not have permission to access the dev dir "/usr/local/lib/node_modules/mip-cli/node_modules/utf-8-validate/.node-gyp/8.11.2"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/mip-cli/node_modules/utf-8-validate/.node-gyp"

阅读 4.8k
5 个回答
第一步给目录加权限:
sudo chmod -R 777 /var/root
第二步安装包
npm install koa  -g --unsafe-perm

并不是npm或者node本身的问题。需要root目录的权限。

换一个node版本

npm坏了,需要重装node

刚刚遇到这个问题也来说一下吧。如果你使用了n包来管理node版本,切换的时候务必要加上sudo,即 sudo n,否则虽然node -v 显示正常,但是install命令就会用不了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题