While updating from Vue 2 to Vue 3 everything is working in development. But when trying to build the app I get a bunch of errors. In Vue 2 build there were no errors.
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import vuetify from 'vite-plugin-vuetify';
import vue from '@vitejs/plugin-vue';
import react from '@vitejs/plugin-react';
import { VitePWA as vitePWA } from 'vite-plugin-pwa';
import { fileURLToPath, URL } from 'node:url';
/**
* Vite Configure
*
* @see {@link https://vitejs.dev/config/}
* @type {import('vite').UserConfig}
*/
export default defineConfig( async ( { command } ) => ( {
// // https://vitejs.dev/config/shared-options.html#base
base: './',
// Resolver
resolve: {
// https://vitejs.dev/config/shared-options.html#resolve-alias
alias: {
'vue': 'vue/dist/vue.runtime.esm-bundler.js',
'@': fileURLToPath( new URL( './resources/js', import.meta.url ) ),
'~': fileURLToPath( new URL( './node_modules', import.meta.url ) ),
ziggy: fileURLToPath( new URL( './vendor/tightenco/ziggy/dist/vue.es.js', import.meta.url ) ),
},
},
// https://vitejs.dev/config/server-options.html
server: {
hmr: {
host: 'localhost',
},
fs: {
// Allow serving files from one level up to the project root
allow: [ '..' ],
},
},
css: {
postcss: {
plugins: [
// Fix vite build includes @charset problem
// https://github.com/vitejs/vite/issues/5655
{
postcssPlugin: 'internal:charset-removal',
AtRule: {
charset: atRule => {
if( atRule.name === 'charset' ) {
atRule.remove();
}
},
},
},
],
},
},
plugins: [
laravel( [ 'resources/js/vue-app.js', 'resources/js/react-app.jsx' ] ),
react({ include: /\.(mdx|js|jsx|ts|tsx)$/ }),
// Vue2
// https://github.com/vitejs/vite-plugin-vue2
vue( {
template: {
transformAssetUrls: {
// The Vue plugin will re-write asset URLs, when referenced
// in Single File Components, to point to the Laravel web
// server. Setting this to `null` allows the Laravel plugin
// to instead re-write asset URLs to point to the Vite
// server instead.
base: '/',
// The Vue plugin will parse absolute URLs and treat them
// as absolute paths to files on disk. Setting this to
// `false` will leave absolute URLs un-touched so they can
// reference assets in the public directory as expected.
includeAbsolute: false,
video: [ 'src', 'poster' ],
source: [ 'src' ],
img: null, // makes it possible to resole images at runtime
image: [ 'xlink:href', 'href' ],
use: [ 'xlink:href', 'href' ],
},
},
} ),
vuetify( { autoImport: true } ),
vitePWA( <config> ),
],
// Build Options
// https://vitejs.dev/config/build-options.html
build: {
// Build Target
// https://vitejs.dev/config/build-options.html#build-target
target: 'modules',
// Rollup Options
// https://vitejs.dev/config/build-options.html#build-rollupoptions
rollupOptions: {
// @ts-ignore
output: {
manualChunks: {
// Split external library from transpiled code.
/* Splitting is possible but will add Vue to React which is unwanted
vue: [
'vue',
],
vuetify: [
'vuetify/lib',
'webfontloader',
],
*/
materialdesignicons: [ '@mdi/font/css/materialdesignicons.css' ],
},
},
},
// Minify option
// https://vitejs.dev/config/build-options.html#build-minify
minify: 'esbuild',
},
esbuild: {
// Drop console when production build.
drop: command === 'serve' ? [] : [ 'console' ],
},
} ) );
Results in the following error:
Error: [vite-plugin-pwa:build] [vite]: Rollup failed to resolve import "fsevents" from "/node_modules/rollup/dist/es/shared/node-entry.js". This is most likely unintended because it can break your application at runtime. If you do want to externalize this module explicitly add it to build.rollupOptions.external at viteWarn (file:///node_modules/vite/dist/node/chunks/dep-BBHrJRja.js:67418:27) at onwarn (file:///node_modules/@vitejs/plugin-react/dist/index.mjs:250:9) at onRollupWarning (file:///node_modules/vite/dist/node/chunks/dep-BBHrJRja.js:67443:9) at onwarn (file:///node_modules/vite/dist/node/chunks/dep-BBHrJRja.js:67150:13) at file:///node_modules/rollup/dist/es/shared/node-entry.js:18303:13 at Object.logger [as onLog] (file:///node_modules/rollup/dist/es/shared/node-entry.js:19950:9) at ModuleLoader.handleInvalidResolvedId (file:///node_modules/rollup/dist/es/shared/node-entry.js:18893:26) at ModuleLoader.resolveDynamicImport (file:///node_modules/rollup/dist/es/shared/node-entry.js:18951:58) at async file:///node_modules/rollup/dist/es/shared/node-entry.js:18838:32
Also tried to add fsevents to the suggested build.rollupOptions.external as external: [ 'fsevents' ], but that gives the following error:
RollupError: [vite-plugin-pwa:build] node_modules/rollup/dist/es/shared/parseAst.js (11:18): "basename" is not exported by "__vite-browser-external", imported by "node_modules/rollup/dist /es/shared/parseAst.js". file: node_modules/rollup/dist/es/shared/parseAst.js:11:18 9: */ 10: import { parse, parseAsync } from '../../native.js'; 11: import { resolve, basename, extname, dirname } from 'node:path'; ^ 12: 13: const ArrowFunctionExpression = 'ArrowFunctionExpression';
Adding rollup-plugin-polyfill-node with external: [ 'fsevents' ] will give the following error:
RollupError: node_modules/@inertiajs/vue3/dist/index.esm.js (1:265): "default" is not exported by "node_modules/lodash.clonedeep/index.js", imported by "node_modules/@inertiajs/vue3/dist/ index.esm.js". file: /nodemodules/@inertiajs/vue3/dist/index.esm.js:1:265 1: import{router as lr}from"@inertiajs/core";import{createHeadManager as q,router as C}from"@inertiajs/core";import{computed as v,defineComponent as B,h as S,markRaw as I,reactive as U,re f as A,shallowRef as J}from"vue";import{router as }from"@inertiajs/core";import L from"lod... ^ 2: 3: Please specify a more appropriate element using the "as" attribute. For example:
Versions:
@inertiajs/core
version: 1.0.15@inertiajs/vue3
version: 1.0.15@inertiajs/react
version: 1.0.15Describe the problem:
While updating from Vue 2 to Vue 3 everything is working in development. But when trying to build the app I get a bunch of errors. In Vue 2 build there were no errors.
package.json
vite.config.js
Results in the following error:
Also tried to add
fsevents
to the suggestedbuild.rollupOptions.external
asexternal: [ 'fsevents' ],
but that gives the following error:Adding
rollup-plugin-polyfill-node
withexternal: [ 'fsevents' ]
will give the following error:Refering to
import L from"lod...
.https://stackoverflow.com/questions/78224761/how-to-resolve-rollup-failed-to-resolve-import-fsevents-during-vite-build
Steps to reproduce:
Run
npm run dev
; everything is working without errors. Runnpm run build
; it's one error after the other.