Skip to content

npm is installed wrongly on windows machine #53538

Closed

Description

@anonrig

I'm getting the following error when trying to run a simple npx command on Windows. I opened the issue to this repository because we are distributing npm, we define the location of npm in a Windows machine.

I reinstalled Node.js from nodejs.org with the latest v22, and I can not use npm at all. Any input/help is appreciated.

PS: I'm using PowerShell.

PS C:\Users\yagiz\Desktop\coding\node> npx node-benchmark-compare .\bench.txt
npm error code ENOENT
npm error syscall lstat
npm error path C:\Users\yagiz\AppData\Roaming\npm
npm error errno -4058
npm error enoent ENOENT: no such file or directory, lstat 'C:\Users\yagiz\AppData\Roaming\npm'
npm error enoent This is related to npm not being able to find a file.
npm error enoent
npm error A complete log of this run can be found in: C:\Users\yagiz\AppData\Local\npm-cache\_logs\2024-06-21T20_29_57_155Z-debug-0.log

cc @nodejs/platform-windows

Activity

  1. added
    windowsIssues and PRs related to the Windows platform.
    on Jun 21, 2024
  2. richardlau commented on Jun 21, 2024

    @richardlau
    Member

    Maybe related to npm/cli#7089?

  3. anonrig commented on Jun 21, 2024

    @anonrig
    MemberAuthor

    cc @nodejs/npm this impacts all windows npm users.

  4. richardlau commented on Jun 21, 2024

    @richardlau
    Member

    Also we used to create AppData\Roaming\npm in the msi installer, but stopped doing so: 0ae8bf8

  5. abrowncownow commented on Jun 21, 2024

    @abrowncownow

    @anonrig Can you post the details of the log C:\Users\yagiz\AppData\Local\npm-cache\_logs\2024-06-21T20_29_57_155Z-debug-0.log

  6. anonrig commented on Jun 21, 2024

    @anonrig
    MemberAuthor

    @anonrig Can you post the details of the log C:\Users\yagiz\AppData\Local\npm-cache\_logs\2024-06-21T20_29_57_155Z-debug-0.log

    0 verbose cli C:\Program Files\nodejs\node.exe C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js
    1 info using npm@10.8.1
    2 info using node@v22.3.0
    3 silly config load:file:C:\Program Files\nodejs\node_modules\npm\npmrc
    4 silly config load:file:C:\Users\yagiz\Desktop\coding\node\.npmrc
    5 silly config load:file:C:\Users\yagiz\.npmrc
    6 silly config load:file:C:\Users\yagiz\AppData\Roaming\npm\etc\npmrc
    7 verbose title npm exec node-benchmark-compare .\bench.txt
    8 verbose argv "exec" "--" "node-benchmark-compare" ".\\bench.txt"
    9 verbose logfile logs-max:10 dir:C:\Users\yagiz\AppData\Local\npm-cache\_logs\2024-06-21T20_29_57_155Z-
    10 verbose logfile C:\Users\yagiz\AppData\Local\npm-cache\_logs\2024-06-21T20_29_57_155Z-debug-0.log
    11 silly logfile start cleaning logs, removing 1 files
    12 silly logfile done cleaning log files
    13 silly packumentCache heap:4345298944 maxSize:1086324736 maxEntrySize:543162368
    14 http fetch GET 200 https://registry.npmjs.org/node-benchmark-compare 152ms (cache revalidated)
    15 silly packumentCache heap:4345298944 maxSize:1086324736 maxEntrySize:543162368
    16 verbose stack Error: ENOENT: no such file or directory, lstat 'C:\Users\yagiz\AppData\Roaming\npm'
    16 verbose stack     at async lstat (node:internal/fs/promises:1026:18)
    16 verbose stack     at async #loadActual (C:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\load-actual.js:112:20)
    16 verbose stack     at async exec (C:\Program Files\nodejs\node_modules\npm\node_modules\libnpmexec\lib\index.js:203:26)
    16 verbose stack     at async Npm.exec (C:\Program Files\nodejs\node_modules\npm\lib\npm.js:207:9)
    16 verbose stack     at async module.exports (C:\Program Files\nodejs\node_modules\npm\lib\cli\entry.js:74:5)
    17 error code ENOENT
    18 error syscall lstat
    19 error path C:\Users\yagiz\AppData\Roaming\npm
    20 error errno -4058
    21 error enoent ENOENT: no such file or directory, lstat 'C:\Users\yagiz\AppData\Roaming\npm'
    22 error enoent This is related to npm not being able to find a file.
    22 error enoent
    23 verbose cwd C:\Users\yagiz\Desktop\coding\node
    24 verbose os Windows_NT 10.0.22631
    25 verbose node v22.3.0
    26 verbose npm  v10.8.1
    27 verbose exit -4058
    28 verbose code -4058
    29 error A complete log of this run can be found in: C:\Users\yagiz\AppData\Local\npm-cache\_logs\2024-06-21T20_29_57_155Z-debug-0.log
    
  7. tniessen commented on Jun 22, 2024

    @tniessen
    Member

    Does npm i -g npm also fail or does it perhaps resolve the issue?

  8. anonrig commented on Jun 23, 2024

    @anonrig
    MemberAuthor

    Does npm i -g npm also fail or does it perhaps resolve the issue?

    It might but running it would destroy the repro in case someone needs it?

  9. lukekarrys commented on Jun 25, 2024

    @lukekarrys
    Member

    @anonrig does it work if you use cmd instead of PowerShell? this is just to figure out if it is also a side effect of #52682

  10. huseyinacacak-janea commented on Jun 26, 2024

    @huseyinacacak-janea
    Contributor

    I've looked into this issue and seen that this is caused by stopping creating AppData\Roaming\npm as @richardlau said. Since this is a security concern, it is unlikely that this commit will be reverted.

    There are workarounds mentioned on the internet. Their basic idea is to create the appropriate folder, either manually by creating an empty folder or by installing a global module. The basic command to create this folder would be npm i -g npm, as this does not install an additional module, but moves the npm folder to global.

    Additionally, you could install the module as an extra step before running npx node-benchmark-compare .\bench.txt. For example, in this case, you could run npm i -g node-benchmark-compare.

    The npx documentation might be misleading for some users. It can be updated accordingly.

    @lukekarrys, I tried from cmd and it is the same.

  11. anonrig commented on Jun 29, 2024

    @anonrig
    MemberAuthor

    This might be a security issue, but regardless we should never ship a broken/buggy software. If this is indeed the default behavior, than I ask myself "why are we shipping a broken feature on Windows?"

    cc @nodejs/tsc

  12. anonrig commented on Jun 29, 2024

    @anonrig
    MemberAuthor

    @anonrig does it work if you use cmd instead of PowerShell? this is just to figure out if it is also a side effect of #52682

    Didn't fix the issue.

  13. added
    npmIssues and PRs related to the npm client dependency or the npm registry.
    tsc-agendaIssues and PRs to discuss during Technical Steering Committee meetings.
    on Jun 29, 2024
  14. anonrig commented on Jun 29, 2024

    @anonrig
    MemberAuthor

    @MylesBorins I think this requires your attention

  15. 20 remaining items

  16. tniessen commented on Jul 5, 2024

    @tniessen
    Member

    It has been 2 weeks, and there is still no solution available from NPM team

    If 0ae8bf8 did indeed re-introduce this issue, then it's been there for more than a year already. I am not sure what the TSC can do about this since we don't maintain npm and no solution has been suggested within Node.js itself.

  17. anonrig commented on Jul 5, 2024

    @anonrig
    MemberAuthor

    @tniessen It means we are shipping unmaintained code for more than a year. How does this don't concern TSC?

  18. targos commented on Jul 5, 2024

    @targos
    Member

    What do you want to discuss in a meeting?

  19. benjamingr commented on Jul 5, 2024

    @benjamingr
    Member

    How does this don't concern TSC?

    You're going to have to accept the fact this isn't in fact a high severity bug from most people's PoV given you're the first one to complain about it afaict and it's been this way for about a year and it's a bug in a third-party program that can be fixed in that program (and it looks like it isn't a high priority for them either).

    When stuff breaks people typically complain very quickly, if you believe this is in error tagging this tsc-agenda multiple times and pinging people multiple times won't help.

    You know exactly what happens when this gets brought up in a TSC meeting:

    • Michael says "ok, the next item on our agenda is npm is installed wrongly on windows machine #53538, anyone here has context to give".
    • Someone volunteers and says "Yagiz asked to add this to the meeting agenda because he thinks it's important and the TSC should look into fixing it".
    • Everyone says "ok", people mention stuff we all already know from this issue like why creating the path was removed (security), the pain (npm can create that path or users need to run another command) etc.
    • someone adds a comment to the meeting notes, nothing gets fixed.

    The TSC is a leadership body not the owner of Node.js, collaborators own the code. You need to motivate someone to fix it or to fix it yourself. You were a TSC voting member you realize how the process works.

    You have a lot of trust, friends and good faith in the project - I feel silly telling you all of this but I feel like you're needlessly frustrated around this all so I felt it's all worth explaining super clearly.

  20. hzhang20902 commented on Jul 9, 2024

    @hzhang20902

    nodejs/help#4436 seems to be reporting a similar issue, are they related?

    don't think so, their issue was non-output to Powershell using npm vs npm.cmd, so most likely an AutoRun config is on their global or user scope for that particular command path. but if their issue wasn't caused by user error or Chocolately/3rd party package manager install (ie at some point the default was changed to enable AutoRun), then it probably would be related as that and this issue affect the same type of system process for command aliasing, however that works under the hood.

  21. anonrig commented on Jul 9, 2024

    @anonrig
    MemberAuthor

    You're going to have to accept the fact this isn't in fact a high severity bug from most people's PoV given you're the first one to complain about it

    @benjamingr I'm not the first one complaining about it. I'm just the first one raising it to the TSC. If you don't think this is not true, here's the result of a quick Google search about this exact problem in the past year and a half.

    Similar issues:

    Stack Overflow:

    Youtube:

    Reddit:

    More websites:

  22. mhdawson commented on Jul 10, 2024

    @mhdawson
    Member

    Was on the TSC agenda as an FYI to raise awareness. It was discussed in meeting today so taking offf the agenda.

  23. removed
    tsc-agendaIssues and PRs to discuss during Technical Steering Committee meetings.
    on Jul 10, 2024
  24. joyeecheung commented on Jul 10, 2024

    @joyeecheung
    Member

    I don't know enough about Windows so pardon my ignorance, but why exactly can't npm create %appdata%\npm when it's missing? nodejs/node-v0.x-archive#8141 described it as

    npm uses $APPDATA\npm so that non-Administrator roles have a writable place to stash global packages. Since creating that directory if it doesn't exist does require Administrator privileges, npm -g install won't / can't work if the base directory doesn't exist (with the correct ACL) before npm is run. The installer should ensure that the whole path is set up at boot time.

    I don't have a Windows machine right now so can't verify but my impression is that creating a folder at %appdata% doesn't require administrator privilege if running user already has access to it (that is, it's not trying to create a folder in the administrator's %appdata% folder when the user running npm isn't administrator). Does that have something to do with the installer having to be run as administrator because it installs things to the program files folder by default? But then the windows installer is not the only way you install Node.js on Windows. nvs, for example, installs Node.js to %localappdata%, so there are no administrator privileges required during installation. It seems fine for npm to at least try creating %appdata\npm if it doesn't exist, and only fail when it cannot actually create that folder, instead of always counting on someone else to create that folder because it assumes only administrators are allowed to do so? (but why?)

  25. leobalter commented on Jul 11, 2024

    @leobalter
    Contributor

    Hi everyone! This might be my first time in a Node forum as the (new) PM for npm. I'm glad to be here!

    Thanks everyone for raising the concerns and the good discussion. I've briefly watched the TSC recording and I agree there are areas for improvement. While the npm i -g npm does the trick, it's not ideal to live with an extra step workaround.

    My team was able to pick this up and a fix should be on the way.

  26. electrovir commented on Aug 2, 2024

    @electrovir

    Oddly, I was unable to get around this issue in GitHub Actions until I ran npm i npm, installing npm directly into my repository. I tried npm i -g npm and it didn't help.

  27. anonrig commented on Aug 2, 2024

    @anonrig
    MemberAuthor

    Issue is fixed with npm/cli#7640

  28. sxlijin commented on Sep 16, 2024

    @sxlijin

    Thanks @anonrig for making sure that this got solved! Our users are running into this issue right now, so I'm glad to see that a fix is in place.

    I'm a bit confused about why it's still happening right now, though, on new installs of Node.js: npm/cli#7640 was merged in July and got released in NPM 10.8.3, if I'm reading npm/cli@9214be9 correctly.

    The various installers currently appear to still ship 10.8.2 by default though (see below image) - I assume because there's some bake time before the next NPM release gets promoted up, but can I ask when NPM 10.8.3 will be shipped by default in the Node.js installer?

    image

  29. added
    installIssues and PRs related to installing Node.js and its installers.
    on Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    installIssues and PRs related to installing Node.js and its installers.npmIssues and PRs related to the npm client dependency or the npm registry.windowsIssues and PRs related to the Windows platform.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions