Open ktabors opened 1 month ago
@ktabors Thank you for submitting an issue!
@layer b {
._5-enzrfpb:lang(ar) {
font-family: myriad-arabic;
}
}
@layer b; // This looks like a syntax error
If I remove it, next build
works normally.
It is valid CSS. @layer
rules don't have to have blocks, they can just declare layer names. This is equivalent to @layer b {}
. See https://drafts.csswg.org/css-cascade-5/#layer-empty, and here for how this behaves in the browser: https://codepen.io/devongovett/pen/YzoxjPM
I suspect cssnano may need to be updated in Next.js (or switch to lightningcss 😉).
Actually I tested in the cssnano playground and it at least doesn't crash there, but still results in incorrect output. Filed a bug there: https://github.com/cssnano/cssnano/issues/1655
I suspect cssnano may need to be updated in Next.js (or switch to lightningcss 😉).
Oh interesting. Let me test it with lightningcss too just in case
FYI, thanks to @snowystinger, this is fixed upstream in cssnano v7.0.5. https://github.com/cssnano/cssnano/pull/1656
@ktabors @devongovett
experimental: {
useLightningcss: true,
}
Can confirm it does not throw on next build
if you use the above. Will look to see now about updating cssnano...
@samcx I tested the experimental
useLightningcss
in the reproduction github repo attached to issue. yarn build
worked with that. The app where this bug occurred is using an older version that doesn't support useLightningcss
. Updating cssnano is preferred.
Hi guys, I am having the exact same error as OP, however useLightningcss: true
doesn't change anything. Is there anything else to be done?
Link to the code that reproduces this issue
https://github.com/ktabors/nextjs-layer-bug
To Reproduce
The project was stripped to nextjs and react. The index.js imports the styles from a css file with the above CSS.
Current vs. Expected behavior
Current:
When building a project the following CSS layers cause cssnano to throw an error.
CSS:
The error:
Expected:
The minifier should not crash during the build step.
Provide environment information
Which area(s) are affected? (Select all that apply)
Output (export/standalone)
Which stage(s) are affected? (Select all that apply)
next build (local)
Additional context
In the project that revealed the error we using a library component. That library component has a CSS file with layers and uses another component with its own CSS file with layers and the layers in the two CSS files have the same names. This creates the order of a layer block at-rule with CSS rules then a layer statement at-rule. Both CSS layers are valid and order shouldn't matter. The second layer should be ignored or treated as
@layer b {}
.