From 1cc739eb0cd1be50d11b934a7502d8f646fca4de Mon Sep 17 00:00:00 2001 From: sapphi-red <49056869+sapphi-red@users.noreply.github.com> Date: Thu, 5 Dec 2024 13:10:51 +0900 Subject: [PATCH] fix: handle postcss load unhandled rejections --- packages/vite/bin/vite.js | 4 ++++ packages/vite/src/node/plugins/css.ts | 15 +++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/vite/bin/vite.js b/packages/vite/bin/vite.js index f42605769ee491..e4d128ac7fa4db 100755 --- a/packages/vite/bin/vite.js +++ b/packages/vite/bin/vite.js @@ -7,6 +7,10 @@ if (!import.meta.url.includes('node_modules')) { // only available as dev dependency await import('source-map-support').then((r) => r.default.install()) } catch {} + + process.on('unhandledRejection', (err) => { + throw new Error('UNHANDLED PROMISE REJECTION', { cause: err }) + }) } global.__vite_start_time = performance.now() diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 8615ba0cf89d22..b3803f4de6c75a 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -307,7 +307,9 @@ export function cssPlugin(config: ResolvedConfig): Plugin { // warm up cache for resolved postcss config if (config.css?.transformer !== 'lightningcss') { - resolvePostcssConfig(config) + resolvePostcssConfig(config).catch(() => { + /* will be handled later */ + }) } return { @@ -1696,9 +1698,14 @@ async function resolvePostcssConfig( return null }) // replace cached promise to result object when finished - result.then((resolved) => { - postcssConfigCache.set(config, resolved) - }) + result.then( + (resolved) => { + postcssConfigCache.set(config, resolved) + }, + () => { + /* keep as rejected promise, will be handled later */ + }, + ) } postcssConfigCache.set(config, result)