通过NPM本地安装Bootstrap时触发EACCES权限错误
解决npm本地安装Bootstrap时的EACCES权限错误
执行命令npm i bootstrap@5.2.3安装Bootstrap时,触发以下权限错误:
npm ERR! syscall open npm ERR! path /Users/samgoldrick/package.json npm ERR! errno -13 npm ERR! Error: EACCES: permission denied, open '/Users/samgoldrick/package.json' npm ERR! [Error: EACCES: permission denied, open '/Users/samgoldrick/package.json'] { npm ERR! errno: -13, npm ERR! code: 'EACCES', npm ERR! syscall: 'open', npm ERR! path: '/Users/samgoldrick/package.json' 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包无异常,但本地项目安装时触发该权限问题,原因及解决方法如下:
问题原因
误在项目目录外(如用户主目录)执行本地安装命令,npm会尝试读取当前目录下的package.json文件,而普通用户没有权限修改主目录下的系统级文件/目录,因此触发EACCES权限错误。
解决步骤
- 执行
pwd命令,确认当前终端所在目录 - 用
cd 你的项目根目录路径切换到项目目录(确保该目录下存在package.json文件) - 再次执行
npm i bootstrap@5.2.3即可完成安装
内容的提问来源于stack exchange,提问作者user10429870
相关产品推荐
相关产品推荐

