cli
cli copied to clipboard
[BUG] npx fails with ENOENT: no such file or directory, lstat 'C:\Users\Stefnotch\AppData\Roaming\npm'
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
- On a Windows machine, install Node.js. I personally installed it with winget.
- Run
npx create-react-app some-name
- If it the error happens, then yay. If not, then go to step 4.
- Go to
%appdata%
(C:\Users\USERNAME\AppData\Roaming) - Delete the
npm
folder. - Run
npx create-react-app some-name
again - 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.
try to create this folder manually
@bondarenkod Yes, creating this folder manually works. But that shouldn't be necessary, because npm (or npm's installer) should take care of it.
try to create this folder manually
yes I fix it manually
@Aimeryyds Can you also confirm having run into this very issue with the current version of npm?
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
Just ran into the same issue. Fixed it by manually creating the folder.
@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 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 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
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.
we are seeing this issue fairly regularly
@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
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 theC:\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
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?
try to create this folder manually
Thanks for the help bro, it worked :)
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
Fixed in #7640
try to create this folder manually
worked for me too
Really helpful. Thanks.