什么可能导致错误Error: EACCES: permission denied, access '/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!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/lib/node_modules' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/macbookmd101/.npm/_logs/2018-02-21T16_26_08_421Z-debug.log

推荐答案

更改文件权限...这样地

首先判断谁拥有这个目录

ls -la /usr/local/lib/node_modules

它拒绝访问,因为 node _模块文件夹归root所有

drwxr-xr-x   3 root    wheel  102 Jun 24 23:24 node_modules

因此,这需要通过将root用户更改为您的用户来改变,但首先运行下面的命令来判断您当前的用户How do I get the name of the active user via the command line in OS X?

id -unwhoami

然后换主人

sudo chown -R [owner]:[owner] /usr/local/lib/node_modules

sudo chown -R ownerName: /usr/local/lib/node_modules

sudo chown -R $USER /usr/local/lib/node_modules

Node.js相关问答推荐

如何在MongoDB中更新嵌套数组

Node.js分页返回空数组

如何发送比特币BTC使用发送加密使用WIF密钥在 node ,js

使用 Google Drive API 按文件夹 ID 检索文件夹的内容

MongoDB - mongoose :如何查询这个? 填充()不起作用.它显示空

只要我在后端正确验证所有内容,就可以将这些数据存储在本地存储中吗?

当我try 从本地主机发布新产品时收到错误消息

WSL2 上需要脚本运行的 NPM 包的权限被拒绝

使用 Node.js 在 MongoDB 中搜索

discordjs如何添加所有意图/权限

2 x 匹配标准显示没有结果

使用中的端口代码:'EADDRINUSE',即使在 kill 命令之后

如何在 mongoDB 中用值 0 填充缺失的文档?

Node.js 表达的 Error 对象expose 了哪些属性?

Puppeteer 错误:未下载 Chromium 修订版

Node.JS 中的基本 HTTP 身份验证?

chart.js 无法创建图表:无法从给定项目获取上下文

PhoneGap/Cordova Android 开发

mongoose 填充与对象嵌套

如何处理来自 express 4 的 FormData