'npx create-react-app not working, file already exists

I have uninstalled create-react-app globally as recommended. Then I ran npx create-react-app test and the following error occured

Error: EEXIST: file already exists, mkdir 'C:\Users\User'
TypeError: Cannot read property 'loaded' of undefined
    at exit (C:\Program Files\nodejs\node_modules\npm\lib\utils\error-handler.js:97: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:81:7
    at Array.forEach (<anonymous>)
    at C:\Program Files\nodejs\node_modules\npm\lib\config\core.js:80: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:171:20)
C:\Program Files\nodejs\node_modules\npm\lib\utils\error-handler.js:97
  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:97:27)
    at process.errorHandler (C:\Program Files\nodejs\node_modules\npm\lib\utils\error-handler.js:216:3)
    at process.emit (events.js:223:5)
    at process._fatalException (internal/process/execution.js:150:25)
Install for [ 'create-react-app@latest' ] failed with code 7

I searched online and tried the following npm cache clean --force. Doesn't work.

I made sure to uninstall create-react-app globally. Then ran which create-react-app

It gives me an error

'which' is not recognized as an internal or external command,
operable program or batch file.

So for now I will have to do npm install -g create-react-app, which is no longer recommended?

If you've previously installed create-react-app globally via npm install -g create-react-app, we recommend you uninstall the package using npm uninstall -g create-react-app to ensure that npx always uses the latest version.

How do I fix this?



Solution 1:[1]

I received the same exact error as you.

I tried the following:

  1. npm cache clean --force, which didn't work for me
  2. Delete node from the system, reinstall it, and then call npx create-react-app <appname>; again, this didn't work for me
  3. Globally install create-react-app using npm install -g create-react-app, followed by the command to create a React app using create-react-app <appname>

At last, after the 3rd step, it worked successfully for me.

Solution 2:[2]

I had this issue too. This worked for me

npx create-react-app@latest <appname>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jeremy Caney
Solution 2 ShaniaKC