Skip to content

Commit 6bacc95

Browse files
fix(config): close bundles when generation fails (#23256)
1 parent e79c471 commit 6bacc95

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

packages/vite/src/node/config.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
type OutputChunk,
2121
type PluginContextMeta,
2222
type RolldownOptions,
23+
type RolldownOutput,
2324
rolldown,
2425
} from 'rolldown'
2526
import { isDynamicPattern } from 'tinyglobby'
@@ -2652,16 +2653,20 @@ export async function bundleConfigFile(
26522653
},
26532654
],
26542655
})
2655-
const result = await bundle.generate({
2656-
format: isESM ? 'esm' : 'cjs',
2657-
sourcemap: 'inline',
2658-
sourcemapPathTransform(relative, sourcemapPath) {
2659-
return path.resolve(path.dirname(sourcemapPath), relative)
2660-
},
2661-
// we want to generate a single chunk like esbuild does with `splitting: false`
2662-
codeSplitting: false,
2663-
})
2664-
await bundle.close()
2656+
let result: RolldownOutput
2657+
try {
2658+
result = await bundle.generate({
2659+
format: isESM ? 'esm' : 'cjs',
2660+
sourcemap: 'inline',
2661+
sourcemapPathTransform(relative, sourcemapPath) {
2662+
return path.resolve(path.dirname(sourcemapPath), relative)
2663+
},
2664+
// we want to generate a single chunk like esbuild does with `splitting: false`
2665+
codeSplitting: false,
2666+
})
2667+
} finally {
2668+
await bundle.close()
2669+
}
26652670

26662671
const entryChunk = result.output.find(
26672672
(chunk): chunk is OutputChunk => chunk.type === 'chunk' && chunk.isEntry,

0 commit comments

Comments
 (0)