首页 > 解决方案 > 使用终端安装 Parcel Bundler 时如何修复权限错误

问题描述

在 nodeJS 中安装 parcel 模块时,通过 Mac OS 上的终端我收到权限错误。错误:checkPermission 缺少对 /usr/local/lib/node_modules 的写访问权限

我是学习节点模块的新手。我尝试安装(节点,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

我想在我的网站上为 Ui 动画安装 Parcel Bundler。

标签: node.jsvisual-studionpmparceljs

解决方案


您需要以/usr/local/lib/node_modules超级管理员的身份访问才能执行parcel-bundler.

正如评论中提到的并假设您的用户是这台计算机的 sudoers 列表,您可以简单地执行以下操作:

sudo npm -g install parcel-bundler

如果不是这种情况,您需要在系统上获得更多权限才能安装 Parcel。然后您将能够:

  • 在文件中将您的用户添加为 sudoers sudoers.d(请小心执行此操作!请参阅OSX 的本教程)。

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

关于计算机本身的长期管理和安全性,我更喜欢第一种选择。另一种选择虽然不推荐,但在某些情况下仍然可行。

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


推荐阅读