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] npx fails with ENOENT: no such file or directory, lstat 'C:\Users\Stefnotch\AppData\Roaming\npm' #7089

Closed
stefnotch opened this issue Dec 17, 2023 · 24 comments
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 10.x

Comments

@stefnotch
Copy link

stefnotch commented Dec 17, 2023

Fixed in #7640 , update to a new version of npm!

This issue has been fixed. Please do npm install -g npm or install a new Node.js

Old Behavior

When running npx create-react-app some-name, then npx throws an error message.

~> npx create-react-app some-name                                                                   12/17/23 10:49:32 AM
npm ERR! code ENOENT
npm ERR! syscall lstat
npm ERR! path C:\Users\Stefnotch\AppData\Roaming\npm
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, lstat 'C:\Users\Stefnotch\AppData\Roaming\npm'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in: C:\Users\Stefnotch\AppData\Local\npm-cache\_logs\2023-12-17T09_49_33_588Z-debug-0.log

This has been fixed in #7640 , update to a new version of npm!

Side note: I originally encountered it after creating a Threlte app, which includes the @threlte/gltf tool. I ran npm run model-pipeline:run in the Threlte app, which runs an npx command under the hood.

This is also a pretty widespread issue, as evidenced by

I suppose it'd be worthwhile to inform these people once it's fixed. I'll happily do so.

Expected Behavior

I expected npx create-react-app some-name to work.
If the folder is missing, then npm should automatically create it.

Steps To Reproduce

  1. On a Windows machine, install Node.js. I personally installed it with winget.
  2. Run npx create-react-app some-name
  3. If it the error happens, then yay. If not, then go to step 4.
  4. Go to %appdata% (C:\Users\USERNAME\AppData\Roaming)
  5. Delete the npm folder.
  6. Run npx create-react-app some-name again
  7. Error should happen

Apparently the npm folder isn't being created by every installer or something. So we can manually reproduce the failure condition.

Environment

  • npm: 10.2.3
  • Node.js: 20.10.0
  • OS Name: Windows 11
  • System Model Name:
  • npm config:
; "builtin" config from C:\Program Files\nodejs\node_modules\npm\npmrc

prefix = "C:\\Users\\Stefnotch\\AppData\\Roaming\\npm"

; node bin location = C:\Program Files\nodejs\node.exe
; node version = v20.10.0
; npm local prefix = C:\Users\Stefnotch
; npm version = 10.2.3
; cwd = C:\Users\Stefnotch
; HOME = C:\Users\Stefnotch
; Run `npm config ls -l` to show all defaults.
@stefnotch stefnotch added Bug thing that needs fixing Needs Triage needs review for next steps Release 10.x labels Dec 17, 2023
@bondarenkod
Copy link

try to create this folder manually

@stefnotch
Copy link
Author

stefnotch commented Dec 21, 2023

@bondarenkod
Yes, creating this folder manually works. But that shouldn't be necessary, because npm (or npm's installer) should take care of it.

Update: This has been fixed in the latest version of npm.

@Aimeryyds
Copy link

try to create this folder manually

yes I fix it manually

@stefnotch
Copy link
Author

@Aimeryyds Can you also confirm having run into this very issue with the current version of npm?

@3limin4t0r
Copy link

This Stack Overflow answer here seem to suggest that this happens when running the command with a different user account than the user who installed npm. Haven't verified this, but this info might be relevant.

https://stackoverflow.com/a/77063477/3982562

@artur-li
Copy link

artur-li commented Feb 27, 2024

Just ran into the same issue. Fixed it by manually creating the folder.

@hzhang20902
Copy link

@bondarenkod Yes, creating this folder manually works. But that shouldn't be necessary, because npm (or npm's installer) should take care of it.

npm install npm -g

@bondarenkod
Copy link

@bondarenkod Yes, creating this folder manually works. But that shouldn't be necessary, because npm (or npm's installer) should take care of it.

npm install npm -g

Nice!
I'm not a pro at the npm world. Just moved here from xamarin.forms, so, a lot of stuff needs to be learn)

@hzhang20902
Copy link

@bondarenkod Yes, creating this folder manually works. But that shouldn't be necessary, because npm (or npm's installer) should take care of it.

npm install npm -g

Nice! I'm not a pro at the npm world. Just moved here from xamarin.forms, so, a lot of stuff needs to be learn)

neither am I, I just try to find people smarter than me and hope they post on the internet 😅
Manually creating the folder seems to be fine for most, but for some people it caused more errors, so this will cleanly install/reinstall npm globally, including the missing directory so there's no worry of node disagreeing with it.

The underlying issue that causes this seems to be:

  • using npm as a different user than the original installer (ie admin for work computers)
  • faux-global installations due to a separation of cloud and local user privileges (user privilege is only global on the work-administered cloud context, not local context)

hope that helped with your learning, I am still learning as well

@KulaGGin
Copy link

KulaGGin commented Apr 29, 2024

The underlying issue that causes this seems to be:

  • using npm as a different user than the original installer (ie admin for work computers)
  • faux-global installations due to a separation of cloud and local user privileges (user privilege is only global on the work-administered cloud context, not local context)

hope that helped with your learning, I am still learning as well

I just downloaded and installed a default node.js after googling nodejs download windows, then following the first link: https://nodejs.org/en/download and then downloading and installing what it proposed, in my case now it's: node-v20.12.2-x64.msi. I got the error when I was trying to create react app with npx create-react-app my-app.

This Stack Overflow answer here seem to suggest that this happens when running the command with a different user account than the user who installed npm. Haven't verified this, but this info might be relevant.

https://stackoverflow.com/a/77063477/3982562

Not in my case. I installed node.js as described above and then immediately ran npx create-react-app my-app and got the error. And the C:\Users\Kulagin\AppData\Roaming\npm was missing, indeed. After I created this folder manually, it successfully created the project.

This seems like a bug that should be fixed on npm and/or on the create-react-app command side.

@joelanman
Copy link

we are seeing this issue fairly regularly

@scshiv29-dev
Copy link

@bondarenkod Yes, creating this folder manually works. But that shouldn't be necessary, because npm (or npm's installer) should take care of it.

npm install npm -g

Thanks this worked for me

@hzhang20902
Copy link

The underlying issue that causes this seems to be:

  • using npm as a different user than the original installer (ie admin for work computers)
  • faux-global installations due to a separation of cloud and local user privileges (user privilege is only global on the work-administered cloud context, not local context)

hope that helped with your learning, I am still learning as well

I just downloaded and installed a default node.js after googling nodejs download windows, then following the first link: https://nodejs.org/en/download and then downloading and installing what it proposed, in my case now it's: node-v20.12.2-x64.msi. I got the error when I was trying to create react app with npx create-react-app my-app.

This Stack Overflow answer here seem to suggest that this happens when running the command with a different user account than the user who installed npm. Haven't verified this, but this info might be relevant.
https://stackoverflow.com/a/77063477/3982562

Not in my case. I installed node.js as described above and then immediately ran npx create-react-app my-app and got the error. And the C:\Users\Kulagin\AppData\Roaming\npm was missing, indeed. After I created this folder manually, it successfully created the project.

This seems like a bug that should be fixed on npm and/or on the create-react-app command side.

node.js and npm aren't the same thing. node.js is a runtime environment to allow js to run on a non-browser env. npm is node package manager, which helps you easily install and manage node modules needed to run things in that environment. npx is node package execution, almost identical to npm exec, and similar to npm run. so yes, its an npm issue. that's why the command is npm install npm

@joyeecheung
Copy link

Maybe it would be better UX if npx can explain the situation a bit more and suggest the workarounds (either installing npm globally or creating the app data folder manually) in the error?

@Ryuu-x
Copy link

Ryuu-x commented Jul 12, 2024

try to create this folder manually

Thanks for the help bro, it worked :)

@stefnotch
Copy link
Author

This issue was also reported at nodejs/node#53538 . There, it got more attention from the right people, as the npm team doesn't seem to be monitoring this issue tracker too closely.

Now we finally have a PR that might fix this issue
#7640 (comment)

@milaninfy
Copy link
Contributor

Fixed in #7640

@EricYoung37
Copy link

try to create this folder manually

worked for me too

@uzairahmed012
Copy link

Really helpful. Thanks.

@atstockland
Copy link

try to create this folder manually

worked for me too

where do you create this folder?

@bondarenkod
Copy link

try to create this folder manually

worked for me too

where do you create this folder?

smthg like that C:\Users\Stefnotch\AppData\Roaming\npm

@hzhang20902
Copy link

Fixed in #7640

can this be pinned to the top of this thread, or somewhere that can be seen by all threads referencing this issue? And I guess w/ "Update to latest" or something. looks like there are still folks trickling in after the fix and doing the ad-hoc solutions.

just in case late-night debugging leads a tired dev down unnecessary rabbit holes 😅

@stefnotch
Copy link
Author

@hzhang20902 Good point, I updated the issue.

@Abduljabbar12
Copy link

try to reinstalling create-react-app using the following command
npm uninstall create-react-app
npm install create-react-app

then, try running the create-react-app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 10.x
Projects
None yet
Development

No branches or pull requests