求助!!为什么nrm安装错误? 更新:按照评论提示,添加了sudo,不报错但是提示警告?更:项目依赖需要升级,执行了npm install -g npm-check-updates,出现警告?

报错如下:

yangqing@KimdeMac-Book-air ~ % npm i nrm -g
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /usr/local/lib/node_modules/nrm
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/nrm'
npm ERR!  [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/nrm'] {
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: '/usr/local/lib/node_modules/nrm'
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:
npm ERR!     /Users/yangqing/.npm/_logs/2023-04-09T06_08_26_546Z-debug-0.log
yangqing@KimdeMac-Book-air ~ % 

提示警告:

npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142

changed 107 packages in 28s

32 packages are looking for funding
  run `npm fund` for details

检查依赖包版本,输入:sudo npm install -g npm-check-updates,出现警告:

npm WARN deprecated @npmcli/move-file@2.0.1: This functionality has been moved to @npmcli/fs
阅读 2k
2 个回答
✓ 已被采纳

这个错误提示是因为您在全局安装 nrm 时,没有足够的权限来创建 /usr/local/lib/node_modules/nrm 目录。您可以尝试使用管理员权限重新运行该命令。在 macOS 或 Linux 终端上,可以使用 sudo 命令来提升权限,如下所示:

sudo npm i nrm -g

Windows 上运行类似命令时,需要在管理员模式下打开命令提示符或 PowerShell。如果您使用的是 Windows 系统,请尝试打开“开始菜单”,搜索“cmd”或“PowerShell”,右键单击它,然后选择“以管理员身份运行”,接着再执行命令。这个错误提示是因为您在全局安装 nrm 时,没有足够的权限来创建 /usr/local/lib/node_modules/nrm 目录。您可以尝试使用管理员权限重新运行该命令。在 macOS 或 Linux 终端上,可以使用 sudo 命令来提升权限,如下所示:

sudo npm i nrm -g

Windows 上运行类似命令时,需要在管理员模式下打开命令提示符或 PowerShell。如果您使用的是 Windows 系统,请尝试打开“开始菜单”,搜索“cmd”或“PowerShell”,右键单击它,然后选择“以管理员身份运行”,接着再执行命令。

报错信息里面提示的很明确了,没有权限。 Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/nrm'

考虑提升一下权限,看用户信息应该是MBA,所以使用 sudu 命令云心 NRM 应该就没问题了。
或者把你的全局依赖的目录写权限修改一下。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题