This repository demonstrates a bug in Lightning CSS where @import layer information is lost when analyzeDependencies is enabled.
This is referenced in the following issues:
When using Lightning CSS's analyzeDependencies option (required for bundlers), the layer() function information from @import rules is lost in the dependency metadata.
Input CSS:
@import url("styles.css") layer(external) not print;Expected dependency object:
{
type: 'import',
url: 'styles.css',
layer: 'external', // ❌ MISSING
media: 'not print'
}Actual dependency object:
{
type: 'import',
url: 'styles.css',
// layer field is missing
media: 'not print'
}This bug breaks:
- Turbopack (used in Next.js) - Cannot preserve CSS cascade layers from import rules
- Any bundler using Lightning CSS with
analyzeDependencies - CSS cascade layer ordering - Critical for modern CSS architecture
- Node.js 18+
- npm
-
Clone this repository
-
Install dependencies:
npm install
-
Run the test:
npm test
The test will show:
- ✅ Without
analyzeDependencies: layer information preserved - ❌ With
analyzeDependencies: layer information missing
- Lightning CSS npm package: v1.30.2 (Rust crate v1.0.0-alpha.68) - Turbopack (Next.js): Uses Rust crate v1.0.0-alpha.68
- Node.js: v20+
- OS: macOS/Linux/Windows
According to the CSS Cascade 5 spec, @import supports:
@import <url> [layer | layer(<layer-name>)]? <media-query-list>?;The layer() function is valid CSS.
This affects:
- Next.js Turbopack users trying to use CSS cascade layers with external imports
- Any project using Lightning CSS in bundler mode that depends on CSS layers
The bug appears to be in the dependency extraction logic. While Lightning CSS correctly:
- ✅ Parses
layer()syntax without errors - ✅ Preserves it in output when not analyzing dependencies
- ✅ Preserves
mediaqueries in dependency metadata
It fails to:
- ❌ Include
layerfield in dependency objects - ❌ Provide any way to recover layer information from dependencies
This makes it impossible for bundlers to reconstruct the original @import with proper layer semantics.