Laravel npm run dev fails: cannot find module '@vitejs/plugin-vue'
Cannot find module '@vitejs/plugin-vue'Short answer
Laravel does not bundle the Vue plugin for Vite. vite.config.js imports @vitejs/plugin-vue, so the package must be in node_modules. Install it with npm install --save-dev @vitejs/plugin-vue, add it to the plugins list with the Laravel options, and make sure your npm install does not skip devDependencies.
Fix it fast
1Find out which cause you have
Check whether the package is in node_modules and in package.json. The two results separate a missing install from an install that was skipped.
npm ls @vitejs/plugin-vue grep -n "plugin-vue" package.json vite.config.js2Match what you see, then jump to its fix
- 1
npm ls prints (empty) and vite.config.js imports @vitejs/plugin-vueThe Vue plugin was never installedFix - 2
The plugin is installed but vite.config.js does not list it in pluginsThe plugin is not added to vite.config.js with the Laravel optionsFix - 3
package.json lists the plugin under devDependencies but node_modules does not have itdevDependencies were skipped by the installFix
- 1
What does the error look like?
Cannot find module '@vitejs/plugin-vue'
Cause 1 of 3
The Vue plugin was never installed
1Check
Laravel's Vite docs say that building a Vue frontend needs the @vitejs/plugin-vue plugin installed separately.
npm ls @vitejs/plugin-vue2Fix
Install it as a development dependency.
npm install --save-dev @vitejs/plugin-vue3Verify
The package now appears in package.json and npm ls shows its version.
npm ls @vitejs/plugin-vueConfirmed by laravel.com
Cause 2 of 3
The plugin is not added to vite.config.js with the Laravel options
1Check
Open vite.config.js. The Laravel docs show the plugin imported and called inside plugins, with transformAssetUrls base set to null and includeAbsolute set to false.
cat vite.config.js2Fix
Import the plugin and add it next to the Laravel plugin.
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import vue from '@vitejs/plugin-vue';
export default defineConfig({
plugins: [
laravel(['resources/js/app.js']),
vue({
template: {
transformAssetUrls: {
base: null,
includeAbsolute: false,
},
},
}),
],
});3Verify
Start the dev server.
npm run devConfirmed by laravel.com
Cause 3 of 3
devDependencies were skipped by the install
1Check
npm skips devDependencies when NODE_ENV is production or --omit=dev / --production is used.
echo $NODE_ENV
npm ls @vitejs/plugin-vue2Fix
Install dev dependencies for the build step, then build. They are only needed at build time.
npm install --include=dev
npm run build3Verify
The build finishes without the module error.
npm run buildConfirmed by docs.npmjs.com
How do I stop it coming back?
- Commit package.json and the lockfile together, and install from them with npm ci in CI.
- On build servers, install dev dependencies for the build step.
- Follow the framework section of the Laravel Vite docs when you add Vue, React or Svelte.
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
Back end
Composer says the gd extension is missing on a Laravel project
composer install or composer update stops on a package that requires ext-gd
Composer refuses to install a package that requires ext-gd when the PHP binary running Composer has no GD extension.
4 causes, each with a fixBack end
composer require maatwebsite/excel fails to install
Composer says the package needs an older PHP than the one installed
Composer refuses maatwebsite/excel when the PHP version or a PHP extension does not match what the package and PhpSpreadsheet need.
3 causes, each with a fixBack end
composer install says the lock file is not compatible and asks for update
Your lock file does not contain a compatible set of packages. Please run composer update.
composer install checked the locked packages against this machine's PHP and extensions and found a conflict.
3 causes, each with a fixBack end
composer require laravel/horizon fails: ext-pcntl is missing
laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system
Horizon needs the pcntl extension, and Composer refuses to install it where PHP lacks that extension.
3 causes, each with a fixBack end
composer require laravel/passport stops with 'requirements could not be resolved'
... but these were not loaded, likely because it conflicts with another require.
Composer found no Passport release that fits your project at once.
4 causes, each with a fixBack end
Composer says the root composer.json requires a PHP version your PHP does not satisfy
Your requirements could not be resolved to an installable set of packages.
Composer compares the php constraint in your composer.json, or in a package, with the PHP that runs Composer.
3 causes, each with a fix