node.js - 如何修复使用终端安装 Parcel Bundler 时的权限错误

标签 node.js visual-studio npm parceljs

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

我是学习 Node 模块的新手。我尝试安装(Node,NPM),一切都很完美。但第一次安装 Node 模块时会抛出错误。我知道它正在寻找 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。

最佳答案

您需要以 super 管理员的身份访问 /usr/local/lib/node_modules,才能执行 parcel-bundler 的全局安装。

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

sudo npm -g install parcel-bundler

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

  • 将您的用户添加为文件 sudoers.d 中的 sudoers(这样做要小心!对于 OSX,请参阅 this tutorial)。

  • 直接以计算机 super 管理员身份进行操作。

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

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

关于node.js - 如何修复使用终端安装 Parcel Bundler 时的权限错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55812369/

相关文章:

javascript - 在 Apache 服务器中运行 NodeJS

javascript - 使用node.js解析多维人口普查数据

c# - 包含文件的 T4 "header guard"

html - ASP CSS 文件停止工作

node.js - 无法在 centos 7 上安装 Angular cli

node.js - 使用 `@zeit/ncc`将Node.js(github Action )编译为单个文件

c# - Visual Studio 中有没有办法将文本转换为 C# 字符串文字?

node.js - Node.js web 应用程序中的 NPM 错误

reactjs - 在react-redux项目中安装节点包时"Error: Cannot find module '内部/util/types '"

node.js - 如何将 Helmet 实现到 Node 服务器中? [没有 express ]