Why Does npm create vite@latest Fail on Windows? (Chocolatey Fix)
I tried to create a new Vite project on Windows:
npm create vite@latestAnd got this frustrating error:
npm ERR! code EPERMnpm ERR! syscall mkdirnpm ERR! path C:\Program Files\nodejs\node_cachenpm ERR! errno -4048npm ERR! Error: EPERM: operation not permitted, mkdir 'C:\Program Files\nodejs\node_cache'npm ERR! [Error: EPERM: operation not permitted, mkdir 'C:\Program Files\nodejs\node_cache'] {npm ERR! errno: -4048,npm ERR! code: 'EPERM',npm ERR! syscall: 'mkdir',npm ERR! path: 'C:\\Program Files\\nodejs\\node_cache'npm ERR! }I spent 3 hours debugging this. I cleared the npm cache multiple times. I ran the terminal as Administrator. I even tried the --force flag. Nothing worked.
The culprit? I had installed Node.js via Chocolatey.
The Root Cause: Chocolatey’s Node.js Installation
When you install Node.js through Chocolatey, it places npm’s cache and global packages in locations that conflict with npm’s expectations on Windows.
Here’s what Chocolatey does differently:
Node.exe location: C:\Program Files\nodejs\NPM cache location: C:\Program Files\nodejs\node_cache\Global packages: C:\Program Files\nodejs\node_modules\PATH modification: SYSTEM PATH (affects all users)The problem is that npm expects to have write access to its cache directory, but C:\Program Files\nodejs\ requires elevated permissions. When npm create vite@latest tries to download and execute the create-vite package, it fails because it cannot write to the cache.
I verified this by checking my npm configuration:
npm config list; "user" config from C:\Users\bswen\.npmrc
cache = "C:\\Program Files\\nodejs\\node_cache"prefix = "C:\\Program Files\\nodejs"The cache location is inside Program Files, which is protected by Windows. This explains the EPERM error.
What I Tried First (And Why It Failed)
Attempt 1: Run as Administrator
npm create vite@latest my-appThis seemed to work initially, but then I got permission errors when trying to run npm inside the project later. Running as Administrator just created more problems - some files were owned by the Administrator account, and my regular user couldn’t modify them.
Attempt 2: Clear npm Cache
npm cache clean --forcenpm WARN using --force Recommended protections disabled.The cache cleared, but the next npm create vite@latest still failed with the same EPERM error. The problem wasn’t a corrupted cache - it was the cache location itself.
Attempt 3: Use npx Instead
npx create-vite@latest my-appSame error. npx uses the same cache location as npm, so it has the same permission issues.
The Real Fix: Uninstall Chocolatey’s Node.js and Reinstall Official Version
Step 1: Uninstall Node.js via Chocolatey
choco uninstall nodejs -yChocolatey v2.2.2Uninstalling the following packages:nodejs
nodejs has been successfully uninstalled.Step 2: Clean Up Remaining Files
Chocolatey sometimes leaves behind files in Program Files:
Remove-Item -Recurse -Force "C:\Program Files\nodejs" -ErrorAction SilentlyContinueRemove-Item -Recurse -Force "$env:APPDATA\npm" -ErrorAction SilentlyContinueRemove-Item -Recurse -Force "$env:APPDATA\npm-cache" -ErrorAction SilentlyContinueStep 3: Download Official Node.js Installer
Go to nodejs.org and download the Windows installer (.msi).
I chose the LTS version (22.x at the time of writing) since Vite requires Node.js version 20.19+ or 22.12+.
Step 4: Run the Official Installer
Run the downloaded .msi file and use the default settings. The official installer sets up npm with proper Windows-compatible paths:
Node.exe location: C:\Program Files\nodejs\NPM cache location: C:\Users\<username>\AppData\Local\npm-cache\Global packages: C:\Users\<username>\AppData\Roaming\npm\PATH modification: User PATH onlyNotice the difference - the npm cache is now in your user directory where you have full write access.
Step 5: Restart Your Terminal
Close and reopen your terminal (or restart your IDE). This refreshes the PATH environment variable.
Step 6: Verify the Installation
node -vv22.12.0npm -v10.9.0Check the new cache location:
npm config get cacheC:\Users\bswen\AppData\Local\npm-cacheThe cache is now in my user directory. No more permission issues.
Step 7: Create Your Vite Project
npm create vite@latestNeed to install the following packages:Ok to proceed? (y) y
> npx create-vite
╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮│ ││ ◇ Project name: ││ │ my-vite-app ││ │ ││ ◇ Package name: ││ │ my-vite-app ││ │ ││ ◇ Select a framework: ││ │ Vue ││ │ ││ ◇ Select a variant: ││ │ TypeScript ││ │ ││ ◇ Scaffolding project in C:\Users\bswen\my-vite-app... ││ │ ││ └────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────│╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯It works.
Why Chocolatey’s Node.js Causes Problems
Chocolatey is great for managing multiple packages, but it doesn’t handle npm’s Windows-specific requirements well.
The official Node.js installer for Windows:
- Places the npm cache in
AppData\Local\npm-cachewhere users have write access - Places global packages in
AppData\Roaming\npm - Adds these paths to the User PATH, not the SYSTEM PATH
Chocolatey’s installer:
- Places everything under
Program Files\nodejs - Modifies the SYSTEM PATH
- Expects npm to work with elevated permissions
This isn’t just a Vite issue. Any npm/npx command that needs to download and execute packages will fail:
npm create react-appnpm create next-appnpm create astro@latestnpx playwright install
Lessons Learned
-
Package managers aren’t always equivalent - Chocolatey’s Node.js package works for running Node.js applications, but it doesn’t set up npm correctly for Windows development.
-
Running as Administrator is rarely the answer - It masks permission issues and creates new problems with file ownership.
-
Check npm config first - When npm commands fail, run
npm config listto see where npm is trying to write files. -
Clearing cache doesn’t fix path problems - If the cache location itself is the problem, cleaning it won’t help.
-
Official installers exist for a reason - For core development tools like Node.js, the official installer is often the most reliable option on Windows.
Alternative: Fix Chocolatey’s Node.js Without Reinstalling
If you prefer to keep using Chocolatey, you can manually fix the npm paths:
npm config set cache "%APPDATA%\npm-cache" --globalnpm config set prefix "%APPDATA%\npm" --globalHowever, this can cause other issues since Chocolatey manages Node.js updates. The next time you upgrade Node.js via choco upgrade nodejs, it might reset these paths. I recommend just using the official installer.
Final Words + More Resources
My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me
Here are also the most important links from this article along with some further resources that will help you in this scope:
- 👨💻 Vite Official Documentation
- 👨💻 Node.js Downloads
- 👨💻 Chocolatey Node.js Package
- 👨💻 Vite GitHub Issues
Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!
Comments