无法使用 npm 在 Mac 上安装 React
Unable to install React on Mac using npm
我试过安装命令 npm install -g create-react-app
但是我收到这样的错误
Ahamad@MacBooks-MacBook-Pro ~ % node -v
v16.15.0
Ahamad@MacBooks-MacBook-Pro ~ % npm -v
8.5.5
Ahamad@MacBooks-MacBook-Pro ~ % npm install -g create-react-app
npm ERR! code EACCES
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/Ahamad/.npm/_logs/2022-05-15T16_46_06_712Z-debug-0.log
Ahamad@MacBooks-MacBook-Pro ~ %
您是否尝试过在命令前添加 sudo ?
sudo npm install -g create-react-app
运行 此命令首先纠正 /usr/local 下的文件所有权:
sudo chown -R $(id -un):$(id -gn) /usr/local/*
然后重新运行 npm install...
你为什么要安装这个?
如果您安装了 npm 和节点,您只需 运行 在您希望创建项目的文件夹中执行以下命令。
注意开头是 NPX 而不是 NPM,这不是错误
npx create-react-app <your app name here>
有关详细信息,请参阅 React Docs
我试过安装命令 npm install -g create-react-app
但是我收到这样的错误
Ahamad@MacBooks-MacBook-Pro ~ % node -v
v16.15.0
Ahamad@MacBooks-MacBook-Pro ~ % npm -v
8.5.5
Ahamad@MacBooks-MacBook-Pro ~ % npm install -g create-react-app
npm ERR! code EACCES
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/Ahamad/.npm/_logs/2022-05-15T16_46_06_712Z-debug-0.log
Ahamad@MacBooks-MacBook-Pro ~ %
您是否尝试过在命令前添加 sudo ?
sudo npm install -g create-react-app
运行 此命令首先纠正 /usr/local 下的文件所有权:
sudo chown -R $(id -un):$(id -gn) /usr/local/*
然后重新运行 npm install...
你为什么要安装这个?
如果您安装了 npm 和节点,您只需 运行 在您希望创建项目的文件夹中执行以下命令。
注意开头是 NPX 而不是 NPM,这不是错误
npx create-react-app <your app name here>
有关详细信息,请参阅 React Docs