How to Fix: Error [ERR_MODULE_NOT_FOUND]: Cannot find package ‘laravel-vite-plugin’ When Running Vite/Laravel Project

Posted by

Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

If youโ€™re working on a Laravel project with Vite, and you see this error:

PS C:\xampp\htdocs\wizbrand-Profile> npm run dev

> dev
> vite

failed to load config from C:\xampp\htdocs\wizbrand-Profile\vite.config.js
error when starting dev server:
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'laravel-vite-plugin' imported from C:\xampp\htdocs\wizbrand-Profile\node_modules\.vite-temp\vite.config.js.timestamp-1754462502397-58092760cee97.mjs
    at Object.getPackageJSONURL (node:internal/modules/package_json_reader:268:9)
    at packageResolve (node:internal/modules/esm/resolve:768:81)
    at moduleResolve (node:internal/modules/esm/resolve:854:18)
    at defaultResolve (node:internal/modules/esm/resolve:984:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:685:12)
    at #cachedDefaultResolve (node:internal/modules/esm/loader:634:25)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:617:38)
    at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:273:38)
    at ModuleJob._link (node:internal/modules/esm/module_job:135:49)

or

failed to load config from ...\vite.config.js

What This Error Means

This error means that your project expects the laravel-vite-plugin package, but it cannot be found in your node_modules. Vite relies on this plugin to integrate properly with Laravel, especially for compiling and hot-reloading your front-end assets.


Common Reasons for This Error

  • The laravel-vite-plugin package is missing from node_modules.
  • Itโ€™s not listed in your package.json dependencies.
  • Your node_modules directory is corrupted or incomplete.
  • Incorrect import style in vite.config.js.
  • Wrong Node.js version (should be v16 or higher for latest Vite/Laravel).
  • You recently cloned the project or switched branches without running npm install.

Step-by-Step Solution

1. Install the Missing Plugin

Run this command in your project root:

npm install laravel-vite-plugin --save-dev

Or with yarn:

yarn add laravel-vite-plugin --dev

This ensures the plugin is added to your devDependencies.


2. Clean and Reinstall All Node Modules (if still failing)

Sometimes, other dependencies are also missing or corrupted. Reset all:

rm -rf node_modules package-lock.json
npm install
  • On Windows, use: rmdir /s /q node_modules del package-lock.json npm install

3. Double-Check Your vite.config.js

At the top, you should see:

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';

export default defineConfig({
  plugins: [
    laravel({
      // ...options
    }),
  ],
});

Donโ€™t use require()โ€”Vite expects ES module (import ... from ...).


4. Check Your Node.js Version

Vite and Laravel Vite Plugin require Node.js v16+.
Check your version:

node -v

If itโ€™s below v16, upgrade Node.js to the latest LTS version.


5. Try Running Again

Start your dev server:

npm run dev

If the error persists, double-check for typos in vite.config.js and ensure thereโ€™s only one version of the plugin in your node_modules.


Extra Tips

  • After switching Git branches or pulling fresh code, always run npm install before running Vite/Laravel Mix.
  • Make sure both laravel-vite-plugin and vite are present in your package.json.
  • Use the latest version of both for best compatibility.

Sample package.json (devDependencies Section)

"devDependencies": {
  "laravel-vite-plugin": "^0.8.0",
  "vite": "^5.0.0"
}

Summary Table

Problem/ReasonSolution
laravel-vite-plugin not installednpm install laravel-vite-plugin --save-dev
Corrupted node_modulesDelete node_modules, reinstall all packages
Wrong import in vite.config.jsUse import laravel from 'laravel-vite-plugin'
Old Node.js versionUpgrade Node.js to v16+

Conclusion

This error is common after fresh clones, branch switches, or missed installs. The solution is almost always to install the missing plugin and ensure a clean node environment.

Still stuck?

  • Double-check your file paths and vite.config.js.
  • Post your full error and relevant configs if you need deeper help!
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x