Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] npm/npx is not handling directories with spaces (on Windows) correctly #502

Closed
kaiyoma opened this issue Nov 19, 2019 · 8 comments
Closed
Labels
Bug thing that needs fixing platform:windows is Windows-specific Wontfix this will not be worked on

Comments

@kaiyoma
Copy link
Contributor

kaiyoma commented Nov 19, 2019

When I try to install packages (specifically, this one: https://www.npmjs.com/package/ts-rws) with the latest version of npm (6.13.0) on Windows 10, I get an error and a stack trace:

error ...\node_modules\ts-rws: Command failed.
Exit code: 7
Command: npx npm-force-resolutions
Arguments:
Directory: ...\node_modules\ts-rws
Output:
Error: EPERM: operation not permitted, mkdir 'C:\Users\Kyle'
TypeError: Cannot read property 'get' of undefined
    at errorMessage (C:\Program Files\Node.js\node_modules\npm\lib\utils\error-message.js:38:39)
    at errorHandler (C:\Program Files\Node.js\node_modules\npm\lib\utils\error-handler.js:201:13)
    at C:\Program Files\Node.js\node_modules\npm\bin\npm-cli.js:78:20
    at cb (C:\Program Files\Node.js\node_modules\npm\lib\npm.js:225:22)
    at C:\Program Files\Node.js\node_modules\npm\lib\npm.js:263:24
    at C:\Program Files\Node.js\node_modules\npm\lib\config\core.js:81:7
    at Array.forEach (<anonymous>)
    at C:\Program Files\Node.js\node_modules\npm\lib\config\core.js:80:13
    at f (C:\Program Files\Node.js\node_modules\npm\node_modules\once\once.js:25:25)
    at afterExtras (C:\Program Files\Node.js\node_modules\npm\lib\config\core.js:171:20)
C:\Program Files\Node.js\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\Node.js\node_modules\npm\lib\utils\error-handler.js:97:27)
    at process.errorHandler (C:\Program Files\Node.js\node_modules\npm\lib\utils\error-handler.js:216:3)

The problem is that npm/npx is not quoting some directory correctly, which results in this:

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

I've been seeing this issue for a long time now (npx commands don't work on Windows), and I've been able to ignore the problem in the past, but now I can't install packages anymore, which is a huge problem. Is there a fix for this?

@kaiyoma
Copy link
Contributor Author

kaiyoma commented Nov 20, 2019

There seem to be multiple layers of issues here and I'm still trying to figure out which package is responsible for the root issue. The stack traces about Cannot read property ... are definitely issues with npm itself. In lib/utils/error-handler.js and lib/utils/error-message.js, I see lots of code of this form:

if (npm.config.foo) // do something

There needs to be an extra check to handle a config that's missing entirely:

if (npm.config && npm.config.foo) // do something

I've made these changes locally and all those errors and stack traces have gone away (but I'm still running into the malformed directory issue).

@fauzanelka
Copy link

Try this

  1. Run npm config edit
  2. Add these lines:
cache=C:\Users\Kyle~1\AppData\Roaming\npm-cache
globalconfig=C:\Users\Kyle~1\AppData\Roaming\npm\etc\npmrc
init-module=C:\Users\Kyle~1\.npm-init.js
tmp=C:\Users\Kyle~1\AppData\Local\Temp
userconfig=C:\Users\Kyle~1\.npmrc
globalignorefile=C:\Users\Kyle~1\AppData\Roaming\npm\etc\npmignore

@kaiyoma
Copy link
Contributor Author

kaiyoma commented Jan 20, 2020

Hey that worked! Oh wow, thanks so much. This was a million times more helpful than the support I received from npm.

@fauzanelka
Copy link

you are welcome :)

darcyclarke pushed a commit that referenced this issue Feb 25, 2020
Sometimes, `npm.config` can be missing entirely, but there are several
places where `npm.config.foo` is accessed blindly, resulting in these
kinds of errors and stack traces:

TypeError: Cannot read property 'get' of undefined
    at errorMessage (.../lib/utils/error-message.js:38:39)
    ...

TypeError: Cannot read property 'loaded' of undefined
    at exit (.../lib/utils/error-handler.js:97:27)
    ...

LBYL by checking `npm.config` first. Addresses a small part of #502.

PR-URL: #508
Credit: @
Close: #508
Reviewed-by: @darcy Clarke
@darcyclarke darcyclarke added platform:windows is Windows-specific Bug thing that needs fixing labels Oct 30, 2020
@bnb
Copy link
Contributor

bnb commented Nov 11, 2020

Just encountered this. It still exists in npm exec and the aliased npx when a user's name includes a space. This means that anyone who has a space in their Windows name will be unable to use npm exec and npx.

@Carson21
Copy link

Carson21 commented Dec 9, 2020

I was having this issue as well but after installing the latest version of npm 7, the problem went away. @bnb

npm install -g npm@7

@bnb
Copy link
Contributor

bnb commented Jan 12, 2021

@darcyclarke seems there are multiple people reporting this solved in npm@7. Maybe either making this wontfix on 6 or backporting the fix is in order?

@darcyclarke darcyclarke added the Wontfix this will not be worked on label Jan 26, 2021
@darcyclarke
Copy link
Contributor

darcyclarke commented Jan 26, 2021

@bnb going to set as wontfix for v6. Definitely open a new ticket if you see this pop up again for v7 though. Current fix/workaround is to grab the latest npm v7 (ex. npm i -g npm@7)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing platform:windows is Windows-specific Wontfix this will not be worked on
Projects
None yet
Development

No branches or pull requests

5 participants