nodejs npm package | npm链接问题

我试图做一个npm包(插件)通过节点安装小JS框架,已经拿出所需的package.json。

在Macterminal上运行npm link命令后,看到以下错误。

npm ERR! Error: EACCES, symlink '/Repos/GIT/JavaScript-Boilerplate' npm ERR! { [Error: EACCES, symlink '/Repos/GIT/JavaScript-Boilerplate'] npm ERR! errno: 3, npm ERR! code: 'EACCES', npm ERR! path: '/Repos/GIT/JavaScript-Boilerplate' } npm ERR! npm ERR! Please try running this command again as root/Administrator. npm ERR! System Darwin 12.3.0 npm ERR! command "node" "/usr/local/bin/npm" "link" npm ERR! cwd /Repos/GIT/JavaScript-Boilerplate npm ERR! node -v v0.10.4 npm ERR! npm -v 1.2.18 npm ERR! path /Repos/GIT/JavaScript-Boilerplate npm ERR! code EACCES npm ERR! errno 3 npm ERR! stack Error: EACCES, symlink '/Repos/GIT/JavaScript-Boilerplate' npm ERR! npm ERR! Additional logging details can be found in: npm ERR! /Repos/GIT/JavaScript-Boilerplate/npm-debug.log npm ERR! not ok code 0 

PS我对nodejs来说很新,但是在JavaScript方面有很强的经验,如果你需要更多的细节,请告诉我。

编辑 – 要解决上面给出的问题,但现在得到更多的问题如下:

 6495 verbose false,/Repos/GIT/JavaScript-Boilerplate/node_modules,/Repos/GIT/JavaScript-Boilerplate/node_modules/jquery/node_modules unbuild contextify@0.1.5 6496 info postuninstall contextify@0.1.5 6497 verbose about to build /Repos/GIT/JavaScript-Boilerplate/node_modules/jquery 6498 info /Repos/GIT/JavaScript-Boilerplate/node_modules/jquery unbuild 6499 verbose from cache /Repos/GIT/JavaScript-Boilerplate/node_modules/jquery/package.json 6500 info preuninstall jquery@1.8.3 6501 info uninstall jquery@1.8.3 6502 verbose true,/Repos/GIT/JavaScript-Boilerplate/node_modules,/Repos/GIT/JavaScript-Boilerplate/node_modules unbuild jquery@1.8.3 6503 info postuninstall jquery@1.8.3 6504 error contextify@0.1.5 install: `node-gyp rebuild` 6504 error `sh "-c" "node-gyp rebuild"` failed with 1 6505 error Failed at the contextify@0.1.5 install script. 6505 error This is most likely a problem with the contextify package, 6505 error not with npm itself. 6505 error Tell the author that this fails on your system: 6505 error node-gyp rebuild 6505 error You can get their info via: 6505 error npm owner ls contextify 6505 error There is likely additional logging output above. 6506 error System Darwin 12.3.0 6507 error command "node" "/usr/local/bin/npm" "link" 6508 error cwd /Repos/GIT/JavaScript-Boilerplate 6509 error node -v v0.10.4 6510 error npm -v 1.2.18 6511 error code ELIFECYCLE 6512 verbose exit [ 1, true ] enter code here enter code here 

看起来像我接近它:)

嘿嘿!

看这些线!

  code EACCES (error acces like acces denied) & Please try running this command again as root/Administrator. ( acces denied ) 

尝试与具有特权的用户。

或者分享这些文件: /Repos/GIT/JavaScript-Boilerplate/npm-debug.log

当您在npm目录npm linknpm install -g等)中进行写操作时,您需要使用安装Node时的权限。

您可能使用根权限运行节点安装,这就是全局程序包安装要求您为root的原因。

解决scheme1:NVM

不要用权限破解,以正确的方式安装节点。

在开发机器上,不应该使用root权限来安装和运行节点,否则像npm linknpm install -g这样的东西需要相同的权限。

NVM (节点版本pipe理器)允许您在没有root权限的情况下安装节点,并且还允许您安装许多版本的节点,以便轻松地与它们一起播放。完美的开发。

  1. 卸载节点(可能需要root权限)。
    • 要删除所有先前安装的npm全局模块,请参阅这些答案 。
  2. 然后按照此页面上的说明安装NVM 。
  3. 通过NVM安装节点: nvm install stable

现在npm linknpm install -g将不再要求你成为root用户。

解决scheme2:为给定用户全局安装软件包

不要用权限破解,以正确的方式在全局安装npm包。

如果您使用的是OSX或Linux,则可以为您的全局程序包创build一个用户专用目录,并设置npmnode以了解如何查找全局安装的程序包。

查看这篇文章 ,详细介绍如何在没有sudo的情况下全局安装npm模块。

另请参阅:npm关于修复npm权限的文档。

解决这个问题的最简单方法是使用sudo再次运行相同的命令:

 sudo npm link 

请不要更改/usr/local目录的所有者,因为这可能会对已安装的应用程序产生进一步的影响,并且可能会危及系统的安全性。 使用sudo是解决这个问题的正确方法。