Why I got Error while Creating React App?

In my case the actual issue was due to the presence of a space in my windows user name folder. Which also appears to be the case here by looking at the first line of the stack trace,

Error: EPERM: operation not permitted, mkdir 'C:\Users\LOGIVAR'

Since there is no directory present named LOGIVAR its trying to run mkdir, for which its getting operation not permitted.

Following is how i fixed it thanks to citoreek, g8up & gijswijs

run npm config edit to edit your config, this will open up a text file in notepad or your configured editor,

then change cache path from

; cache=C:\Users\Gijs van Dam\AppData\Roaming\npm-cache

to

cache=C:\Users\GIJSVA~1\AppData\Roaming\npm-cache

Remember to remove the ; at the start, next question would be how do we know to replace our user name with GIJSVA~1?

There are a couple of ways to target this,

  1. Go to C:\Users open power Shell and execute following command

cmd /c dir /x

what this does is, list down all the directories in current directory along with their short names which aren't supposed to contain any spaces and normally are 6 characters or less in length. Copy that short name against your user name directory and use this in your cache path.

You will notice these short names only exist for directories either containing spaces or which are longer than 6 characters, for the rest of the directories their short names will be same as their directory name,

  1. If you don't want to use above command, then simply remove all the spaces from your user name in your cache path, then take the first 6 characters of the user directory name and postfix it with ~1. You should also uppercase it, but it appears not to be making any difference.

After you are done with editing this file, save your changes then try again after closing any active power shell / bash process and reopening them.


  1. First to install globally

    npm install -g create-react-app
    
  2. Create your new app

    npx create-react-app your-app-name
    

    this worked for me


Have you tried running this as admin?

Tags:

Npm

Reactjs