9
votes

I am using node js 11.13.0 and npm above 6.0 by which I am trying to setup react js app in Windows by following command:

npx create-react-app new-app

and the output is coming as :

Error: EPERM: operation not permitted, mkdir 'C:\Users\Talha' TypeError: Cannot read property 'loaded' of undefined at exit (C:\Program Files\nodejs\node_modules\npm\lib\utils\error-handler.js:98:27) at errorHandler (C:\Program Files\nodejs\node_modules\npm\lib\utils\error-handler.js:216:3) at C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js:78:20 at cb (C:\Program Files\nodejs\node_modules\npm\lib\npm.js:225:22) at C:\Program Files\nodejs\node_modules\npm\lib\npm.js:263:24 at C:\Program Files\nodejs\node_modules\npm\lib\config\core.js:83:7 at Array.forEach () at C:\Program Files\nodejs\node_modules\npm\lib\config\core.js:82:13 at f (C:\Program Files\nodejs\node_modules\npm\node_modules\once\once.js:25:25) at afterExtras (C:\Program Files\nodejs\node_modules\npm\lib\config\core.js:173:20) C:\Program Files\nodejs\node_modules\npm\lib\utils\error-handler.js:98 var doExit = npm.config.loaded ? npm.config.get('_exit') : true ^

TypeError: Cannot read property 'loaded' of undefined at exit (C:\Program Files\nodejs\node_modules\npm\lib\utils\error-handler.js:98:27) at process.errorHandler (C:\Program Files\nodejs\node_modules\npm\lib\utils\error-handler.js:216:3) at process.emit (events.js:193:13) at process._fatalException (internal/process/execution.js:123:25) Install for create-react-app@latest failed with code 7

I don't find a way to figure out the solution.

2
Did you end up solving this problem? I have it too.Mathias Lykkegaard Lorenzen

2 Answers

11
votes

There are two reasons why this might happen.

  1. You are not running in an elevated cmd prompt.
  2. You have spaces in your username or path npm is looking for cache. For eg. "c:\Users\Fname Lastname...."

For the first one you can try running npx create-react-app newapp in an elevated cmd prompt. (Launching cmd as admin)

For the second one you would have to replace the username on the path for npm config that has spaces with the alternative username windows generates which you can get by using the cmd DIR /X if you are in the location. "c:\Users\". After getting the alternative name you then run

npm config set cache "C:\Users\Firstname~1\AppData\Roaming\npm-cache" --global

where Firstname~1 is the alternative name you got from the DIR /X command. You should now be able to run npx create-react-app new-app with no errors.

More information on this can be found here

3
votes

December 2020

I had the same error. It seems to be because of the whitespace in the User's name. The simplest solution is to update npm to the latest version. Run npm install -g npm@7 and you should be able to run npx create-react-app new-app without issues.