Maaz Zindani

Loading the index…

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

npm run dev in Laravel cannot find vite.js

ErrorError: Cannot find module 'C:\vite\bin\vite.js'

Short answer

The dev script runs the vite command from node_modules. If that file is missing, npm install did not finish, was never run, or the command runs outside the project root. Run npm install in the folder that holds package.json, and use a Node.js version Vite supports.

  • Applies to Laravel 12, Node.js 22, Windows 11
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check that you are in the Laravel project root and that Vite is installed there.

    node -v
    ls package.json node_modules/vite
  2. 2Match what you see, then jump to its fix

    1. 1node_modules is missing, or node_modules/vite does not exist.Frontend dependencies were never installed or were interruptedFix
    2. 2node -v shows an old version, and npm install prints engine warnings.The Node.js version is too old for ViteFix
    3. 3ls package.json finds nothing in the current folder.The command runs from a folder that is not the project rootFix

What does the error look like?

  • Error: Cannot find module 'C:\vite\bin\vite.js'
  • npm run dev exits right after starting, with a module error

Cause 1 of 3

Frontend dependencies were never installed or were interrupted

1Check

A fresh Laravel project ships a package.json with Vite and the Laravel plugin, but you still have to run npm install.

npm ls vite laravel-vite-plugin

2Fix

Install the dependencies from the project root. If a half-finished install left a broken folder, remove node_modules first.

rm -rf node_modules
npm install

3Verify

The dev server starts.

npm run dev

Confirmed by laravel.com

Did this fix it?

Cause 2 of 3

The Node.js version is too old for Vite

1Check

Vite's guide requires Node.js 20.19+ or 22.12+.

node -v

2Fix

Install a supported Node.js version from the official site or a version manager, then reinstall.

nvm install 22
nvm use 22
npm install

3Verify

Run the dev script again.

npm run dev

Confirmed by vite.dev

Did this fix it?

Cause 3 of 3

The command runs from a folder that is not the project root

1Check

Laravel keeps package.json and vite.config.js in the project root, and the scripts depend on that.

pwd

2Fix

Change into the project root and run the script there.

cd /path/to/your-laravel-app
npm run dev

3Verify

Vite prints its local dev server address.

npm run dev

Confirmed by laravel.com

Did this fix it?

How do I stop it coming back?

  • Run npm install after every git clone or composer create-project.
  • Pin the Node.js version in .nvmrc.
  • Keep node_modules out of Git and rely on the lock file.

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

Next step

Want this handled for good?

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