Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

timtinan37's avatar

Laravel Vite build error: 'resolve' is not exported by __vite-browser-externaL

I'm trying to build and version the assets for production in a Laravel project. I'm using laravel-vite-plugin version 0.6.1, node version v16.17.1, npm version 8.19.2. For this, when I run npm run build, I get the following error.

> 'resolve' is not exported by __vite-browser-external, imported by node_modules/vite/dist/node/constants.js
>     file: /var/www/html/node_modules/vite/dist/node/constants.js:1:15
>     1: import path, { resolve } from 'node:path';
>                     ^
>     2: import { fileURLToPath } from 'node:url';
>     error during build:
>     Error: 'resolve' is not exported by __vite-browser-external, imported by node_modules/vite/dist/node/constants.js
>         at error (file:///var/www/html/node_modules/rollup/dist/es/shared/rollup.js:1858:30)
>         at Module.error (file:///var/www/html/node_modules/rollup/dist/es/shared/rollup.js:12429:16)
>         at Module.traceVariable (file:///var/www/html/node_modules/rollup/dist/es/shared/rollup.js:12788:29)
>         at ModuleScope.findVariable (file:///var/www/html/node_modules/rollup/dist/es/shared/rollup.js:11440:39)
>         at Identifier.bind (file:///var/www/html/node_modules/rollup/dist/es/shared/rollup.js:7439:40)
>         at CallExpression.bind (file:///var/www/html/node_modules/rollup/dist/es/shared/rollup.js:5269:23)
>         at CallExpression.bind (file:///var/www/html/node_modules/rollup/dist/es/shared/rollup.js:8935:15)
>         at VariableDeclarator.bind (file:///var/www/html/node_modules/rollup/dist/es/shared/rollup.js:5269:23)
>         at VariableDeclaration.bind (file:///var/www/html/node_modules/rollup/dist/es/shared/rollup.js:5265:73)
>         at Program.bind (file:///var/www/html/node_modules/rollup/dist/es/shared/rollup.js:5265:73)

Below is my Vite configuration.

vite.config.js

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

export default defineConfig({
    plugins: [
        laravel({
            input: [
                'resources/scss/style.scss',
                'resources/scss/theme.scss',
                'resources/js/bundle.js',
                'resources/js/scripts.js',
                'resources/js/charts/analytics-chart.js',
            ],
            refresh: true,
        }),
    ],
});
0 likes
4 replies
timtinan37's avatar

@Mahmoud_Awad I'm not sure how my problems were fixed. I removed all the implicit imports from my js files, and that somehow fixed my problems. So, double check that you are importing third party packages properly in your js files and avoid implicit imports. If that doesn't fix your problem, than try running npm run build on a fresh laravel installation. If you don't face the problem in fresh laravel, then add your js files one by one and run npm run build. Debug following small steps like this, hopefully you'll be able to identify the original cause behind this.

Please or to participate in this conversation.