npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/local/lib/node_modules
npm ERR! errno -13
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!
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/tal/.npm/_logs/2024-08-23T10_29_14_483Z-debug.log
这个错误是由于权限问题导致的。你当前用户没有权限访问 /usr/local/lib/node_modules 目录。通常在全局安装 npm 包时会遇到这个问题,因为全局安装目录需要管理员权限。
使用 sudo 命令
你可以使用 sudo 提升权限来安装全局包:
sudo npm install -g <package-name>
在输入这条命令时,系统会要求你输入管理员密码(电脑登录密码)。