【问题标题】:nodejs npm package | npm link issuenodejs npm 包 | npm 链接问题
【发布时间】:2013-04-27 17:49:40
【问题描述】:

我正在尝试制作一个npm包(插件)来通过node安装小JS框架,也想出了所需的package.json。

在 Mac 终端上运行 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

附:我是 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

看起来我很接近它:)

【问题讨论】:

  • 我已经修复了一些 package.json 值,现在它给了我以下问题:module.js:340 throw err; ^ 错误:Function.Module._resolveFilename (module.js:338:15) at Function.Module._load (module.js:280:25) at Function 找不到模块'/Repos/GIT/JavaScript-Boilerplate/link' .Module.runMain (module.js:497:10) 在启动时 (node.js:119:16) 在 node.js:901:3

标签: node.js npm


【解决方案1】:

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

sudo npm link

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

【讨论】:

    【解决方案2】:

    在执行诸如写入 npm 目录npm linknpm install -g 等)之类的操作时,将需要您在安装 Node 时使用的权限。

    您可能以 root 权限运行节点安装,这就是全局包安装要求您成为 root 的原因。


    解决方案 1:NVM

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

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

    NVM(Node 版本管理器)允许您在没有 root 权限的情况下安装 Node,还允许您安装多个版本的 Node 以轻松使用它们。非常适合开发。

    1. 卸载节点(可能需要 root 权限)。
      • 要删除所有以前安装的 npm 全局模块,请参阅那些 answers
    2. 然后按照说明on this page 安装NVM
    3. 通过 NVM 安装节点:nvm install stable

    现在npm linknpm install -g 将不再要求您是 root。


    解决方案 2:为给定用户全局安装软件包

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

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

    查看this great article,了解在不使用 sudo 的情况下全局安装 npm 模块的分步说明。

    另请参阅:npm 在Fixing npm permissions 上的文档。

    【讨论】:

      【解决方案3】:

      这可以通过将全局包目录设置为用户空间而不是根目录在 linux 或在我的情况下的 WSL 中解决。

      首先为全局包创建一个目录

      mkdir ~/.npm-packages
      

      然后告诉 npm 在哪里存储全局安装的包

      npm config set prefix ~/.npm-packages
      

      通过将以下内容添加到您的 .bashrc/.zshrc 中,最后确保 npm 能够找到已安装的二进制文件和手册页:

      NPM_PACKAGES=~/.npm-packages
      export PATH="$PATH:$NPM_PACKAGES/bin"
      # Preserve MANPATH if you already defined it somewhere in your config.
      # Otherwise, fall back to `manpath` so we can inherit from `/etc/manpath`.
      export MANPATH="${MANPATH-$(manpath)}:$NPM_PACKAGES/share/man"
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-03-13
        • 1970-01-01
        • 2021-09-30
        • 2022-06-30
        • 2016-12-24
        • 1970-01-01
        相关资源
        最近更新 更多