Repository navigation
Replies: 2 comments
|
You can promote this specific warning through Vite's import { createLogger, defineConfig } from 'vite';
const logger = createLogger();
const originalWarnOnce = logger.warnOnce;
logger.warnOnce = (message, options) => {
if (message.includes("didn't resolve at build time")) {
throw new Error(message);
}
originalWarnOnce(message, options);
};
export default defineConfig({ customLogger: logger });I tested this on Vite 8.3.3: a missing CSS |
|
There's no built-in option for that, Vite treats unresolved // vite.config.ts
import { createLogger, defineConfig } from 'vite'
const logger = createLogger()
const warn = logger.warn
logger.warn = (msg, options) => {
if (msg.includes("didn't resolve at build time")) throw new Error(msg)
warn(msg, options)
}
export default defineConfig({ customLogger: logger })Throwing propagates through the build so the process exits non-zero and CI catches it. If you'd rather collect every unresolved reference first and fail at the end, push them to an array in the warn hook and throw in a — |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I have a build in which I’d like to ensure all the asset references in my CSS successfully resolve. At the moment, I get a warning like:
…which is great, but the exit code is 0, and this is just a warning. Is there any way to make Vite treat this as an error instead? I’ve looked through the documentation and, if there’s an option, I’m certainly missing it!
(Obviously I can work around it my capturing stderr and grepping for the problems I’m concerned about… or maybe failing if there’s anything on on stderr, but it would be nice if I didn’t have to do that. As-is, I need to at least be careful about debug output on stderr. Not sure if there can be other non-warning/error output on stderr.)
All reactions