Home > front end >  Unable to install React on Mac using npm
Unable to install React on Mac using npm

Time:05-16

I have tried installing the command npm install -g create-react-app But i get an error like this

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 ~ % 

CodePudding user response:

Have you tried adding sudo in front of your command ?

sudo npm install -g create-react-app

CodePudding user response:

Why are you trying to install this?

If you have npm and node installed you need to simply run the following command in the folder where you wish to create your project.

Note the NPX and not NPM at the start, this isn't a mistake

npx create-react-app <your app name here>

For more information see React Docs

CodePudding user response:

Run this command first to rectify files ownership under /usr/local :

sudo chown -R $(id -un):$(id -gn) /usr/local/*

then rerun npm install...

  • Related