I am trying to install create-react-app globally using npm with the following command:
npm install -g create-react-app
However, I am encountering the following error:
npm ERR! code EACCES
npm ERR! syscall rename
npm ERR! path /usr/local/lib/node_modules/create-react-app
npm ERR! dest /usr/local/lib/node_modules/.create-react-app-DgI96EzL
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, rename '/usr/local/lib/node_modules/create-react-app' -> '/usr/local/lib/node_modules/.create-react-app-DgI96EzL'
npm ERR! [Error: EACCES: permission denied, rename '/usr/local/lib/node_modules/create-react-app' -> '/usr/local/lib/node_modules/.create-react-app-DgI96EzL'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'rename',
npm ERR! path: '/usr/local/lib/node_modules/create-react-app',
npm ERR! dest: '/usr/local/lib/node_modules/.create-react-app-DgI96EzL'
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
I have tried the following solutions but none of them worked:
sudo npm install -g create-react-app
Changing the ownership of the npm directories
Installing npm packages without root access by changing the npm prefix.
None of these solutions have resolved the issue. How can I fix this permission error and successfully install create-react-app globally?
Change ownership of the npm directories to the current user:
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
or
Use npx to create a React app without global installation This is the simplest method and avoids the need to install create-react-app globally:
npx create-react-app my-app