Skip to content

Commit d5fb653

Browse files
authored
fix: handle postcss load unhandled rejections (#18886)
1 parent 2b5926a commit d5fb653

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

packages/vite/bin/vite.js

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ if (!import.meta.url.includes('node_modules')) {
77
// only available as dev dependency
88
await import('source-map-support').then((r) => r.default.install())
99
} catch {}
10+
11+
process.on('unhandledRejection', (err) => {
12+
throw new Error('UNHANDLED PROMISE REJECTION', { cause: err })
13+
})
1014
}
1115

1216
global.__vite_start_time = performance.now()

packages/vite/src/node/plugins/css.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,9 @@ export function cssPlugin(config: ResolvedConfig): Plugin {
307307

308308
// warm up cache for resolved postcss config
309309
if (config.css?.transformer !== 'lightningcss') {
310-
resolvePostcssConfig(config)
310+
resolvePostcssConfig(config).catch(() => {
311+
/* will be handled later */
312+
})
311313
}
312314

313315
return {
@@ -1696,9 +1698,14 @@ async function resolvePostcssConfig(
16961698
return null
16971699
})
16981700
// replace cached promise to result object when finished
1699-
result.then((resolved) => {
1700-
postcssConfigCache.set(config, resolved)
1701-
})
1701+
result.then(
1702+
(resolved) => {
1703+
postcssConfigCache.set(config, resolved)
1704+
},
1705+
() => {
1706+
/* keep as rejected promise, will be handled later */
1707+
},
1708+
)
17021709
}
17031710

17041711
postcssConfigCache.set(config, result)

0 commit comments

Comments
 (0)