You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
npm is installed wrongly on windows machine #53538
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
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.
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?"
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.
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:
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.
Reacted by Tobias Nießen
Reacted by Ruy Adorno, Michaël Zasso, Marco Ippolito and Aviv Keller
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.
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.
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?)
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.
Reacted by Tobias Nießen
Reacted by Joyee Cheung, Benjamin Gruenbaum, Jordan Harband and Hudson Nguyen
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.
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?
Activity
richardlau commentedon Jun 21, 2024
Maybe related to npm/cli#7089?
anonrig commentedon Jun 21, 2024
cc @nodejs/npm this impacts all windows npm users.
richardlau commentedon Jun 21, 2024
Also we used to create
AppData\Roaming\npmin the msi installer, but stopped doing so: 0ae8bf8abrowncownow commentedon Jun 21, 2024
@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.loganonrig commentedon Jun 21, 2024
tniessen commentedon Jun 22, 2024
Does
npm i -g npmalso fail or does it perhaps resolve the issue?anonrig commentedon Jun 23, 2024
It might but running it would destroy the repro in case someone needs it?
lukekarrys commentedon Jun 25, 2024
@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
huseyinacacak-janea commentedon Jun 26, 2024
I've looked into this issue and seen that this is caused by stopping creating
AppData\Roaming\npmas @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 runnpm 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.
anonrig commentedon Jun 29, 2024
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
anonrig commentedon Jun 29, 2024
Didn't fix the issue.
anonrig commentedon Jun 29, 2024
@MylesBorins I think this requires your attention
20 remaining items
tniessen commentedon Jul 5, 2024
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.
anonrig commentedon Jul 5, 2024
@tniessen It means we are shipping unmaintained code for more than a year. How does this don't concern TSC?
targos commentedon Jul 5, 2024
What do you want to discuss in a meeting?
benjamingr commentedon Jul 5, 2024
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:
npmis installed wrongly on windows machine #53538, anyone here has context to give".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.
hzhang20902 commentedon Jul 9, 2024
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.
anonrig commentedon Jul 9, 2024
@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:
mhdawson commentedon Jul 10, 2024
Was on the TSC agenda as an FYI to raise awareness. It was discussed in meeting today so taking offf the agenda.
joyeecheung commentedon Jul 10, 2024
I don't know enough about Windows so pardon my ignorance, but why exactly can't npm create
%appdata%\npmwhen it's missing? nodejs/node-v0.x-archive#8141 described it asI 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\npmif 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?)leobalter commentedon Jul 11, 2024
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 npmdoes 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.
electrovir commentedon Aug 2, 2024
Oddly, I was unable to get around this issue in GitHub Actions until I ran
npm i npm, installingnpmdirectly into my repository. I triednpm i -g npmand it didn't help.anonrig commentedon Aug 2, 2024
Issue is fixed with npm/cli#7640
sxlijin commentedon Sep 16, 2024
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?