当我尝试安装nodemon时,我收到此错误消息

问题描述 投票:0回答:4
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /usr/local/lib/node_modules/nodemon
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir'/usr/local/lib/node_modules/nodemon'
npm ERR!  [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/nodemon'] {
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: '/usr/local/lib/node_modules/nodemon'
npm ERR! }
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.


npm ERR! A complete log of this run can be found in:

看起来问题出在包生成器-业力上,不确定这是否是问题。

任何人都可以告诉我我需要做什么才能正确安装。

谢谢 萨尼尔

node.js express terminal command nodemon
4个回答
1
投票

我相信您正在尝试使用

npm install -g nodemon
在系统上安装全局包,然后权限被拒绝,这显示在错误消息中。

没有 root 权限,您无法安装全局包。如果你想这样做,只需使用 root 权限执行即可,例如使用 sudo:

sudo npm i -g nodemon
或切换到 root 然后再次执行。


0
投票

这看起来像是您的主目录中的权限问题。要回收 node_modules 目录的所有权,请执行:

sudo chown -R $(whoami) ~/node_modules

0
投票

Node.js 错误

EACCES
意味着您无权访问它指定的路径。在这种情况下,
/usr/local/lib/...
root
用户拥有。请参阅此处的命令输出:

$ ls -l /usr/local/lib

total 12
drwxr-xr-x 4 root root  4096 Apr  7 23:45 node_modules

除了 root 之外,任何人都不能写入

node_modules
文件夹。这可以通过在 npm 命令前添加
sudo
来运行命令 as root 来解决。

查看其他:了解 Linux 文件权限 - Linuxize


0
投票

使用 npm 脚本: 您也可以在本地安装“nodemon”,而不是全局安装 您项目的目录并将其用作 npm 脚本。首先,导航到您的 项目目录然后运行:

npm install --save-dev nodemon
© www.soinside.com 2019 - 2024. All rights reserved.