Skip to content

Commit

Permalink
chore(css): catch postcss config error (fix #2793) (#7934)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Apr 27, 2022
1 parent 50672e4 commit 7f535ac
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/vite/src/node/plugins/css.ts
Expand Up @@ -942,14 +942,22 @@ async function resolvePostcssConfig(
plugins: inlineOptions.plugins || []
}
} else {
const searchPath =
typeof inlineOptions === 'string' ? inlineOptions : config.root
try {
const searchPath =
typeof inlineOptions === 'string' ? inlineOptions : config.root
// @ts-ignore
result = await postcssrc({}, searchPath)
} catch (e) {
if (!/No PostCSS Config found/.test(e.message)) {
throw e
if (e instanceof Error) {
const { name, message, stack } = e
e.name = 'Failed to load PostCSS config'
e.message = `Failed to load PostCSS config (searchPath: ${searchPath}): [${name}] ${message}\n${stack}`
e.stack = '' // add stack to message to retain stack
throw e
} else {
throw new Error(`Failed to load PostCSS config: ${e}`)
}
}
result = null
}
Expand Down

0 comments on commit 7f535ac

Please sign in to comment.