AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

CSS Url() Imports Resolve Incorrectly When Using MatchResource (`!=!`) With Mini-Css-Extract-Plugin

The bundled mini-css-extract-plugin v2.4.4 in Next.js does not respect matchResource (`!=!`) in importModule, causing relative asset paths in CSS url() to resolve against the wrong directory. This breaks asset references for any webpack loader using matchResource to emit CSS. Fixed upstream in mini-css-extract-plugin v2.10.2.

highConfidence 95%Next.js

Origin Analysis

mini-css-extract-plugin's importModule ignores the matchResource string from `!=!` requests, resolving url() paths against the original file context instead of the matchResource context. This is an upstream bug fixed in mini-css-extract-plugin v2.10.2 (webpack-contrib/mini-css-extract-plugin#1162).
1. Create a webpack loader that uses matchResource (`!=!`) syntax to emit CSS through mini-css-extract-plugin. 2. Include a CSS url() reference to a relative asset (e.g., url(./image.png)). 3. Build with `next build --webpack`. 4. Observe that the url() path resolves against the wrong directory, resulting in broken asset references.

Fixing Code Block

Edge Case Audit

Upgrading mini-css-extract-plugin may require a compatible webpack version. Verify that Next.js's webpack version supports the new plugin version. Test CSS extraction, HMR, and asset resolution thoroughly. If any new regressions appear, roll back to the previous bundled version. Also ensure no loaders depend on the old incorrect behavior.

Ecosystem Topology