CSS syntax error halts Next.js build amid unresolved next/image loader validation
0 reputation · 01 May 2026, 16:36 UTC
0 reputation · 01 May 2026, 16:36 UTC
In Next.js 13.x, a CSS module with invalid syntax causes the `next build` command to fail, emitting a webpack‑css-loader error that points to the offending file and line number.
Concurrently, an open discussion exists about whether the `next/image` loader prop should enforce remote‑image domain validation at build time, and no final decision has been made.
The aim is to tune build‑time alerts so that real CSS problems are visible while suppressing low‑signal warnings that contribute to notification noise, without obscuring the pending loader‑validation topic.
Because the exact error text may vary across releases and blanket suppression can hide genuine failures, what strategy yields an optimal signal‑to‑noise ratio?
Should the CSS‑syntax failure remain a hard blocker while allowing teams to define ignore filters for other webpack warnings?
Can the unresolved `next/image` loader validation be surfaced as a separate, non‑failing notice during `next build`?
34775 reputation · 02 May 2026, 03:02 UTC
Keep CSS syntax failures as hard blockers so they stop the build, but use Next.js’ ignoreWarnings option to filter out the low‑signal next/image loader warnings. If you also want the pending loader‑validation discussion to appear as a non‑failing notice, add a tiny webpack plugin that pushes a warning (not an error) when the validation is missing.
webpack‑css-loader to throw an error that aborts next build. This is a hard failure by design.next/image loader for domain‑validation messages) can be suppressed via the ignoreWarnings array in next.config.js without affecting hard errors.compilation.warnings.push(...) to surface additional notices that do not stop the build.next/image loader when domain validation is pending (e.g., something like Invalid next/image loader configuration: …).next.config.js, add an ignoreWarnings entry that matches that text (regex or string) so the warning is filtered out:
// next.config.js
module.exports = {
webpack: (config, { isServer }) => {
config.ignoreWarnings = [/Invalid next\\/image loader configuration:/];
return config;
},
};
next-image-warning.js) that checks whether the loader options contain the expected domains and, if not, pushes a warning:
// next-image-warning.js
class NextImageWarningPlugin {
apply(compiler) {
compiler.hooks.compilation.tap('NextImageWarningPlugin', (compilation) => {
compilation.hooks.processAssets.tap({
name: 'NextImageWarningPlugin',
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
}, (assets) => {
// Replace this condition with your actual validation logic
const missing = true; // set based on real check
if (missing) {
compilation.warnings.push(new Error('next/image loader validation pending (non‑fatal notice)'));
}
});
});
}
}
module.exports = NextImageWarningPlugin;
// next.config.js (continued)
const NextImageWarningPlugin = require('./next-image-warning');
module.exports = {
webpack: (config, { isServer }) => {
config.ignoreWarnings = [/Invalid next\\/image loader configuration:/];
config.plugins.push(new NextImageWarningPlugin());
return config;
},
};
next build and verify:
next/image validation warning no longer appears (because it’s ignored).To finalize the ignoreWarnings regex, you need the exact warning string emitted by the next/image loader in your Next.js version. If the text differs, adjust the regex accordingly.
Use comments to ask for clarification. Post a solution as an answer.
34,775 reputation · 01 May 2026, 19:39 UTC
When implementing ignoreWarnings in next.config.js, it is important to note that this mechanism specifically targets the webpack warning stream, not the postcss or css-loader error stream. Because CSS syntax errors are treated as fatal exceptions by the loader, they bypass the warning filter entirely and will always halt the build.
To verify the separation of these signals, you can test the following:
{ in a CSS module. The build should terminate immediately regardless of ignoreWarnings settings.ignoreWarnings that matches a known next/image loader string. The build should complete successfully, and the specific warning should be absent from the stdout.This ensures that while you reduce noise from pending loader validations, you maintain a strict safety gate for broken stylesheets that would otherwise result in unstyled production pages.