cli icon indicating copy to clipboard operation
cli copied to clipboard

[BUG] npx fails with ENOENT: no such file or directory, lstat 'C:\Users\Stefnotch\AppData\Roaming\npm'

Open stefnotch opened this issue 1 year ago • 14 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

This issue exists in the latest npm version

  • [X] I am using the latest npm

Current 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

(I can provide the log if necessary)

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

  • https://github.com/npm/cli/issues/6971
  • https://stackoverflow.com/questions/77152589/cannot-find-npm-on-appdata-roaming
  • https://stackoverflow.com/questions/76635661/npm-shows-an-error-enoent-no-such-file-or-directory-when-creating-a-react-pro
  • https://stackoverflow.com/questions/76635661/npm-shows-an-error-enoent-no-such-file-or-directory-when-creating-a-react-pro
  • https://www.youtube.com/watch?v=UwY6U7L10lg
  • https://www.youtube.com/watch?v=mxyRDd-xKv4
  • https://www.reddit.com/r/nextjs/comments/15x1w60/guys_getting_this_error_while_creating_a_next_app/

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 avatar Dec 17 '23 09:12 stefnotch

try to create this folder manually

bondarenkod avatar Dec 21 '23 00:12 bondarenkod

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

stefnotch avatar Dec 21 '23 08:12 stefnotch

try to create this folder manually

yes I fix it manually

Aimeryyds avatar Dec 27 '23 10:12 Aimeryyds

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

stefnotch avatar Dec 27 '23 10:12 stefnotch

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

3limin4t0r avatar Feb 08 '24 14:02 3limin4t0r

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

artur-li avatar Feb 27 '24 09:02 artur-li

@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

hzhang20902 avatar Mar 26 '24 02:03 hzhang20902

@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)

bondarenkod avatar Mar 26 '24 21:03 bondarenkod

@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

hzhang20902 avatar Mar 28 '24 23:03 hzhang20902

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.

KulaGGin avatar Apr 29 '24 08:04 KulaGGin

we are seeing this issue fairly regularly

joelanman avatar May 01 '24 12:05 joelanman

@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

scshiv29-dev avatar May 11 '24 21:05 scshiv29-dev

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

hzhang20902 avatar May 15 '24 01:05 hzhang20902

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?

joyeecheung avatar Jun 29 '24 10:06 joyeecheung

try to create this folder manually

Thanks for the help bro, it worked :)

Ryuu-x avatar Jul 12 '24 03:07 Ryuu-x

This issue was also reported at https://github.com/nodejs/node/issues/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 https://github.com/npm/cli/pull/7640#issuecomment-2223820848

stefnotch avatar Jul 12 '24 06:07 stefnotch

Fixed in #7640

milaninfy avatar Jul 12 '24 20:07 milaninfy

try to create this folder manually

worked for me too

EricYoung37 avatar Jul 21 '24 20:07 EricYoung37

Really helpful. Thanks.

uzairahmed012 avatar Aug 21 '24 12:08 uzairahmed012