npm - EPERM mkdir: operation not permitted on Windows

Solution 1:

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

Solution 2:

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.