Skip to content

Why Does npm create vite@latest Fail on Windows? (Chocolatey Fix)

I tried to create a new Vite project on Windows:

terminal
npm create vite@latest

And got this frustrating error:

error output
npm ERR! code EPERM
npm ERR! syscall mkdir
npm ERR! path C:\Program Files\nodejs\node_cache
npm ERR! errno -4048
npm 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:

Chocolatey Node.js paths
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:

terminal
npm config list
npm config output
; "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

terminal (as Admin)
npm create vite@latest my-app

This 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

terminal
npm cache clean --force
output
npm 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

terminal
npx create-vite@latest my-app

Same 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

terminal
choco uninstall nodejs -y
output
Chocolatey v2.2.2
Uninstalling the following packages:
nodejs
nodejs has been successfully uninstalled.

Step 2: Clean Up Remaining Files

Chocolatey sometimes leaves behind files in Program Files:

terminal (PowerShell as Admin)
Remove-Item -Recurse -Force "C:\Program Files\nodejs" -ErrorAction SilentlyContinue
Remove-Item -Recurse -Force "$env:APPDATA\npm" -ErrorAction SilentlyContinue
Remove-Item -Recurse -Force "$env:APPDATA\npm-cache" -ErrorAction SilentlyContinue

Step 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:

Official Node.js 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 only

Notice 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

terminal
node -v
output
v22.12.0
terminal
npm -v
output
10.9.0

Check the new cache location:

terminal
npm config get cache
output
C:\Users\bswen\AppData\Local\npm-cache

The cache is now in my user directory. No more permission issues.

Step 7: Create Your Vite Project

terminal
npm create vite@latest
output
Need 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:

  1. Places the npm cache in AppData\Local\npm-cache where users have write access
  2. Places global packages in AppData\Roaming\npm
  3. Adds these paths to the User PATH, not the SYSTEM PATH

Chocolatey’s installer:

  1. Places everything under Program Files\nodejs
  2. Modifies the SYSTEM PATH
  3. 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-app
  • npm create next-app
  • npm create astro@latest
  • npx playwright install

Lessons Learned

  1. 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.

  2. Running as Administrator is rarely the answer - It masks permission issues and creates new problems with file ownership.

  3. Check npm config first - When npm commands fail, run npm config list to see where npm is trying to write files.

  4. Clearing cache doesn’t fix path problems - If the cache location itself is the problem, cleaning it won’t help.

  5. 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:

terminal
npm config set cache "%APPDATA%\npm-cache" --global
npm config set prefix "%APPDATA%\npm" --global

However, 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:

Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!

Comments