如何在终端安装 Parcel Bundler 时修复权限错误问题

5
在Mac OS的终端中安装nodeJS的parcel模块时,我遇到了权限错误。 错误:checkPermission缺少对/usr/local/lib/node_modules的写访问权限。
我刚开始学习Node模块,尝试安装(Node,NPM),一切都正常。但是第一次安装节点模块时会抛出错误。我知道它正在寻找类似Windows类型URL的目录,但我不知道如何为Mac解决此问题。
iMac:~ hassan$ node -v
v11.10.0 
iMac:~ hassan$ npm -v
6.7.0
iMac:~ hassan$ npm install -g parcel-bundler
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR!  { [Error: EACCES: permission denied, access '/usr/local/lib/node_modules']
npm ERR!   stack:
npm ERR!    "Error: EACCES: permission denied, access '/usr/local/lib/node_modules'",
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/lib/node_modules' }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/hassan/.npm/_logs/2019-04-23T13_13_46_848Z-debug.log

我想在我的网站上安装Parcel打包程序,用于UI动画。


1
如果你真的想要全局安装这个包(即使用 -g 标志),你需要使用 sudo npm install -g parcel-bundler - Chris White
相同的问题,但使用sudo命令执行该命令会得到相同的结果。还尝试首先使用以下命令设置目录: sudo chown -R $USER ~/.npm
sudo chown -R $USER /usr/lib/node_modules
sudo chown -R $USER /usr/local/lib/node_modules(附注:抱歉没有换行符,显然Markdown在这里不起作用?)
- tronster
1个回答

2
您需要访问/usr/local/lib/node_modules,就像超级管理员一样,才能执行parcel-bundler的全局安装。
如评论中所述,并假设您的用户是此计算机的sudoers列表,您可以简单地执行以下操作:
sudo npm -g install parcel-bundler

如果不是这种情况,您需要在系统上拥有更多的权限才能安装Parcel。然后您就可以:
  • 将您的用户添加到sudoers.d文件中(这样做要小心!有关OSX的详细信息请参见this tutorial)。

  • 直接以计算机的超级管理员身份执行操作。

就长期管理和计算机本身的安全而言,我更喜欢第一种选择。尽管不建议使用另一种选择,但对于某些情况仍然可能使用。

否则,如果选择在本地安装Parcel,则不会出现权限错误。在这种情况下,只需在运行命令时省略-g标志即可(即npm install parcel-bundler)。它最终将parcel添加到您的package.json文件中,以便稍后再次安装它。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接