Maaz Zindani

Loading the index…

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

Laravel npm run dev fails: cannot find module '@vitejs/plugin-vue'

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

  • Applies to Laravel 11, Laravel 12, Vite 5, Vite 6, npm 10
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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.js
  2. 2Match what you see, then jump to its fix

    1. 1npm ls prints (empty) and vite.config.js imports @vitejs/plugin-vueThe Vue plugin was never installedFix
    2. 2The 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. 3package.json lists the plugin under devDependencies but node_modules does not have itdevDependencies were skipped by the installFix

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-vue

2Fix

Install it as a development dependency.

npm install --save-dev @vitejs/plugin-vue

3Verify

The package now appears in package.json and npm ls shows its version.

npm ls @vitejs/plugin-vue

Confirmed by laravel.com

Did this fix it?

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

2Fix

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 dev

Confirmed by laravel.com

Did this fix it?

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-vue

2Fix

Install dev dependencies for the build step, then build. They are only needed at build time.

npm install --include=dev
npm run build

3Verify

The build finishes without the module error.

npm run build

Confirmed by docs.npmjs.com

Did this fix it?

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

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

Next step

Want this handled for good?

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