npm on Windows fails because the AppData\Roaming\npm folder is missing
Error: ENOENT, stat 'C:\Users\<user>\AppData\Roaming\npm'Short answer
npm on Windows keeps global packages in the folder %AppData%\npm by default. If that folder does not exist, or the prefix points somewhere else, npm stops with ENOENT. Check the prefix with npm config get prefix, create the folder as your normal user, or set the prefix to a folder that exists.
Fix it fast
1Find out which cause you have
Print the prefix npm uses for global packages and test whether that folder exists.
npm config get prefix Test-Path "$env:APPDATA\npm"2Match what you see, then jump to its fix
What does the error look like?
Error: ENOENT, stat 'C:\Users\<user>\AppData\Roaming\npm'
Cause 1 of 2
The global folder was never created
1Check
The npm common-errors page lists this ENOENT stat error for that exact path and says the folder must exist and be writable by your normal user account.
Test-Path "$env:APPDATA\npm"
echo $env:APPDATA2Fix
Create the folder in a normal (not administrator) PowerShell, so your user owns it.
New-Item -ItemType Directory -Force "$env:APPDATA\npm"3Verify
Run the command that failed again, for example a global install.
Test-Path "$env:APPDATA\npm"
npm config get prefixConfirmed by docs.npmjs.com
Cause 2 of 2
The prefix points to a folder that does not exist
1Check
The npm folders documentation says that on Windows the global prefix defaults to %AppData%\npm. A prefix set in an npmrc file overrides the default. npm config list shows what is set.
npm config list
npm config get prefix2Fix
Delete the stale setting to return to the default, or set the prefix to a folder you created.
npm config delete prefix
# or point it at a folder that exists
npm config set prefix "$env:APPDATA\npm"3Verify
The prefix is now a folder that exists.
npm config get prefix
Test-Path (npm config get prefix)Confirmed by docs.npmjs.com
How do I stop it coming back?
- Create global folders and run npm as your normal user, not as Administrator.
- Keep prefix overrides in one npmrc file and write down why.
- After moving or restoring a Windows profile, check the prefix once with npm config get prefix.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
ng serve says it cannot determine the project or target
Cannot determine project for command.
The Angular CLI looked through angular.json for a project that defines the target you asked for (serve, build, test) and found none, or found several and could not pick one.
3 causes, each with a fixBack end
ng fails with Cannot find module @angular/cli/bin/ng
Cannot find module '@angular/cli/bin/ng'
The ng command is the entry point to the Angular CLI package.
2 causes, each with a fixBack end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fixBack end
ng serve cannot find the dev-server builder package
Could not find the implementation for builder @angular/build:dev-server
The builder named in angular.json (for example @angular-devkit/build-angular:dev-server) is looked up as an npm package starting from the workspace root.
3 causes, each with a fixBack end
Angular build says it cannot resolve '@angular/localize/init'
Can't resolve '@angular/localize/init' in '/usr/src/app/src'
The build imports @angular/localize, and that package is not in node_modules.
2 causes, each with a fixBack end
The command npm run build -- --prod exited with code 1 (Angular)
The command "npm run build -- --prod" exited with code 1
Exit code 1 only says the build failed; the real message is above it.
2 causes, each with a fix