npm/npx

npx throwing Error : EPERM : operation not permitted with spaces in path : on windows

Opened this issue · 14 comments

npx returns above Error while running npx create-react-app my-app

This error is due to spaces in username or in path
like : C:\Users\Rohit Bakoliya

node --version 
v12.16.1 (even with v13.11.0 and v10.16.3)
npm --version
16.13.4
npx --version
16.13.4

##Error Log

C:\Users\UserName>npx create-react-app practical-react
Error: EPERM: operation not permitted, mkdir 'C:\Users\UserName'
TypeError: Cannot read property 'loaded' of undefined
at exit (D:\Program Files D\nodejs\node_modules\npm\lib\utils\error-handler.js:98:27)
at errorHandler (D:\Program Files D\nodejs\node_modules\npm\lib\utils\error-handler.js:216:3)
at D:\Program Files D\nodejs\node_modules\npm\bin\npm-cli.js:77:20
at cb (D:\Program Files D\nodejs\node_modules\npm\lib\npm.js:225:22)
at D:\Program Files D\nodejs\node_modules\npm\lib\npm.js:263:24
at D:\Program Files D\nodejs\node_modules\npm\lib\config\core.js:83:7
at Array.forEach (<anonymous>)
at D:\Program Files D\nodejs\node_modules\npm\lib\config\core.js:82:13
at f (D:\Program Files D\nodejs\node_modules\npm\node_modules\once\once.js:25:25)
at afterExtras (D:\Program Files D\nodejs\node_modules\npm\lib\config\core.js:173:20)
D:\Program Files D\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 (D:\Program Files D\nodejs\node_modules\npm\lib\utils\error-handler.js:98:27)
at process.errorHandler (D:\Program Files D\nodejs\node_modules\npm\lib\utils\error-handler.js:216:3)
at process.emit (events.js:198:13)
at process._fatalException (internal/bootstrap/node.js:496:27)
Install for create-react-app@latest failed with code 7

.npmrc contains wrong path
in my case : it is prefix=C:\Users\Rohit
I tried to change it to correct path.
but its not working.

Similar issue, My username is two words with a space, this seems to be a long standing issue.

PS C:\Users\David R\Documents\react_tutorial1> npx create-react-app my-app
Error: EPERM: operation not permitted, mkdir 'C:\Users\David'
TypeError: Cannot read property 'get' of undefined
    at errorMessage (C:\Program Files\nodejs\node_modules\npm\lib\utils\error-message.js:38:39)
    at errorHandler (C:\Program Files\nodejs\node_modules\npm\lib\utils\error-handler.js:201:13)
    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:311:20)
    at process._fatalException (internal/process/execution.js:164:25)
Install for [ 'create-react-app@latest' ] failed with code 7

Original Bug here: zkat/npx#100

Windows 10 1909
Node v12.16.1
npm 6.13.4
npx 6.13.4

Looks like the solution and pull request were done here: zkat/npx#181

I'm new to javascript / node / npm but looks like since the solution is already done I might be able to do the work to create a pull request to get this merged in. I don't really want to waste my time if its just going to end up like previous PR though. Please let me know if I can be of help here.

Work-around until this almost 3 year old bug is fixed:

Windows PowerShell with admin rights:

new-item -itemtype Junction -Path 'C:\Users\' -Name 'UserNameWithSpaces' -Target 'C:\Users\User Name With Spaces\'
npm config set cache C:\Users\UserNameWithSpaces\
npm config set prefix C:\Users\UserNameWithSpaces\

Workaround that worked for me: npm install -g create-react-app before.

I have fixed this issue with the following steps:
-- step 1: open your git bash and run this command "npm install -g create-react-app" or "yarn global add create-react-app".

-- step 2: navigate to this directory "C:\Users{YOUR_USERNAME}\AppData\Roaming\npm" and open git bash.

-- step 3: re-run "npx create-react-app my-app".

*Note: Please step-by-step, NOT JUMP OR SKIP.

@rohitbakoliya That's a workaround that requires extra software and steps, and the bug still persist.
I'd keep this issue open to give it visibility and hopefully reach a fix for it

EDIT
Related with #14 , so maybe duplicated?

Maintainer isn't going to do anything about it anyways:
#30 (comment)

That's not what that comment says; it says they definitely are going to do something about it, later.

Workaround for this 3 year old bug:

cmd /c mklink /J "C:\Users\firstnamelastname" "C:\Users\Firstname Lastname\"

npm config set cache C:\Users\firstnamelastname\AppData\Roaming\npm-cache

npm config set prefix C:\Users\firstnamelastname\AppData\Roaming\npm

Original workaround from another git comment section. Shamelessly copied.

Related to: #6