Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

npm run dev cannot find Vite: Cannot find module vite\bin\vite.js

ErrorError: Cannot find module 'C:\foo\bar&baz\vite\bin\vite.js'

Short answer

The dev script runs the vite binary from node_modules. If you never ran npm install, or Vite is not in devDependencies, that binary does not exist. On Windows, an & in the folder path also breaks npm. Install Vite as a dev dependency, or move the project to a path without &.

  • Applies to Vite 8, Node.js 22, npm 10
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check that Vite is listed and that its binary exists in this project.

    npm ls vite
    ls node_modules/.bin/vite
  2. 2Match what you see, then jump to its fix

    1. 1npm ls shows (empty), or node_modules does not existDependencies were never installed, or Vite is missing from package.jsonFix
    2. 2The module path in the error contains &The project path contains an ampersand on WindowsFix

What does the error look like?

  • Error: Cannot find module 'C:\foo\bar&baz\vite\bin\vite.js'

Cause 1 of 2

Dependencies were never installed, or Vite is missing from package.json

1Check

A fresh clone has no node_modules. Also confirm the scripts section runs plain vite.

grep -n -A4 '"scripts"' package.json

2Fix

Install the dependencies. If Vite is not listed at all, add it as a dev dependency, and use the standard scripts.

npm install
npm install -D vite

3Verify

Start the server. Vite serves at http://localhost:5173 by default.

npx vite

Confirmed by vite.dev

Did this fix it?

Cause 2 of 2

The project path contains an ampersand on Windows

1Check

npm on Windows breaks when a folder name has an & in it.

cd

2Fix

Rename or move the project to a path without &, or use pnpm or Yarn.

move "C:\foo\bar&baz" "C:\foo\barbaz"

3Verify

Run the dev script from the new path.

npm run dev

Confirmed by vite.dev

Did this fix it?

How do I stop it coming back?

  • Run npm install (or npm ci in CI) after every clone and every branch change that touches package.json.
  • Keep project folder names free of an ampersand.

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

Web apps

Vite cannot read your vite.config file

Cannot find module

Vite loads vite.config as a file in its own right, and it must be detected as ESM by Node.js if it uses import and export.

3 causes, each with a fix

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 fix

Back 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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.