如何修复此错误?
安装 Node.js 并将其添加到路径后,我在 iTerm2 上运行了以下命令
npm install -g create-react-app
我收到以下错误
npm ERR! syscall mkdir
npm ERR! path /usr/local/lib/node_modules/create-react-app
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/create-react-app'
npm ERR! [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/create-react-app'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/usr/local/lib/node_modules/create-react-app'
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/amaterasu/.npm/_logs/2022-01-04T08_36_06_018Z-debug.log ```
我今天早些时候遇到了这个问题,这就是我修复它的方法。
npm uninstall -g create-react-app
npx clear-npx-cache
npx create-react-app my-app
如果您对有关此问题的详细信息感兴趣,请查看此 github 线程
对于想要全局安装的npm包,主要可能会遇到权限问题。这通常可以通过在行首添加 sudo 来解决。所以代替:
create-react-app yourAppName
你可以这样做:
sudo npx create-react-app yourAppName
遵循您的 root 用户密码。
此外,要添加更多内容,还报告了一些有关 Node js 版本和创建 React 应用程序的问题。您可以在终端上通过以下命令检查 Mac 中安装的节点版本:
node --version
如果安装的Node版本是17.X,则可以认为与该问题有关。
始终建议使用 LTS 版本。
您需要有 Node.js 版本 14(或更高版本)和 npm 5.6(或更高版本)。
为 React 项目创建一个文件夹。 在终端(命令行)中打开该文件夹。 并使用
npx create-react-app yourAppName
。
上述错误与权限有关。您无权在“/usr/local/lib/node_modules/create-react-app”下创建新文件夹。
如果仍然出现此错误,请使用
sudo npx create-react-app yourAppName
。