Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vite build hangs forever

when I run vite build aka npm run build the build performs without errors.

I see built in 4661ms. but the process never finishes. It just hangs.

How can I make the process end and exit?

like image 744
Stephani Bishop Avatar asked Nov 16 '25 17:11

Stephani Bishop


1 Answers

You can easily exit Vite by hooking into the buildEnd and closeBundle events.

Define a plugin as follows:

// file vite-plugin-close.ts

export default function ClosePlugin() {
    return {
        name: 'ClosePlugin', // required, will show up in warnings and errors

        // use this to catch errors when building
        buildEnd(error) {
            if(error) {
                console.error('Error bundling')
                console.error(error)
                process.exit(1)
            } else {
                console.log('Build ended')
            }
        },

        // use this to catch the end of a build without errors
        closeBundle(id) {
            console.log('Bundle closed')
            process.exit(0)
        },
    }
}

Import the plugin in your vite.config.ts

// file vite.config.ts

import ClosePlugin from './vite-plugin-close.ts'
// ...

// place the plugin in the *vite* plugins section
// NOT the rollupOptions.plugins section
        plugins: [ClosePlugin()],

The same thing applies for JS files, just switch the extensions.

✓ 3662 modules transformed.
dist/bundle/cli.js 8,825.66 kB
Bundle closed
(base) ➜ cli git:(main) ✗

like image 125
forgetso Avatar answered Nov 19 '25 10:11

forgetso



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!