nextjs - 💡(How to fix) Fix [Turbopack] @import layer() attributes stripped in dev mode, work in production [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#85029Fetched 2026-04-08 02:17:41
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Author
Timeline (top)
closed ×1commented ×1labeled ×1locked ×1

Turbopack (Next.js dev mode with --turbopack) strips layer() and media query attributes from @import statements. Production builds with Webpack preserve these correctly.

This is caused by an upstream bug in Lightning CSS's dependency analysis mode.

Root Cause

Turbopack uses Lightning CSS (v1.0.0-alpha.62) for CSS parsing. When Lightning CSS's analyzeDependencies mode is enabled (required for bundling), it drops the layer information from import dependency metadata.

Upstream Issue: https://github.com/parcel-bundler/lightningcss/issues/1074

Fix Action

Workaround

Disable Turbopack for development:

{
  "scripts": {
    "dev": "next dev"  // Remove --turbopack flag
  }
}

Or use @layer blocks instead of import attributes:

@import url('https://unpkg.com/papercss/dist/paper.min.css');

@layer external {
  /* Unfortunately this doesn't work for external imports */
}

Code Example

/* app/global-styles/global.css */
@import url('https://unpkg.com/papercss/dist/paper.min.css') layer(external) not print;

.test {
  color: blue;
}

---

next dev --turbopack

---

next build

---

@import url('...') layer(external) not print;

---

@import url('...');  /* layer() and not print are stripped */

---

@import url('...') layer(external) not print;  /* ✅ correct */

---

{
  "scripts": {
    "dev": "next dev"  // Remove --turbopack flag
  }
}

---

@import url('https://unpkg.com/papercss/dist/paper.min.css');

@layer external {
  /* Unfortunately this doesn't work for external imports */
}

---

Operating System:
  Platform: darwin
  Arch: arm64
Binaries:
  Node: 20.x
  pnpm: 10.18.2
Relevant Packages:
  next: 15.5.6
  react: 19.2.0
  react-dom: 19.2.0

---

@import <url> [layer | layer(<layer-name>)]? <media-query-list>?;
RAW_BUFFERClick to expand / collapse

Description

Turbopack (Next.js dev mode with --turbopack) strips layer() and media query attributes from @import statements. Production builds with Webpack preserve these correctly.

This is caused by an upstream bug in Lightning CSS's dependency analysis mode.

To Reproduce

Minimal Repo

https://github.com/aneuhold/lightningcss-layer-bug

Steps

  1. Create a Next.js app with the following CSS:
/* app/global-styles/global.css */
@import url('https://unpkg.com/papercss/dist/paper.min.css') layer(external) not print;

.test {
  color: blue;
}
  1. Run in dev mode with Turbopack:
next dev --turbopack
  1. Check the browser dev tools - the @import is missing the layer(external) not print attributes

  2. Build for production and run:

next build
  1. Check the output CSS in .next/static - the attributes are correctly preserved

Expected Behavior

Both dev and production should preserve:

@import url('...') layer(external) not print;

Actual Behavior

Dev mode (Turbopack):

@import url('...');  /* layer() and not print are stripped */

Production (Webpack):

@import url('...') layer(external) not print;  /* ✅ correct */

Root Cause

Turbopack uses Lightning CSS (v1.0.0-alpha.62) for CSS parsing. When Lightning CSS's analyzeDependencies mode is enabled (required for bundling), it drops the layer information from import dependency metadata.

Upstream Issue: https://github.com/parcel-bundler/lightningcss/issues/1074

Technical Details

Lightning CSS correctly:

  • ✅ Parses @import ... layer() syntax
  • ✅ Preserves it in output when not analyzing dependencies
  • ✅ Preserves media queries in dependency metadata

But fails to:

  • ❌ Include layer field in dependency objects when analyzeDependencies: true

This makes it impossible for Turbopack to reconstruct the @import with proper layer semantics.

Impact

  • CSS Cascade Layers cannot be used with external imports in Turbopack
  • Inconsistent behavior between dev and production
  • Breaking changes when switching from Webpack to Turbopack

Workaround

Disable Turbopack for development:

{
  "scripts": {
    "dev": "next dev"  // Remove --turbopack flag
  }
}

Or use @layer blocks instead of import attributes:

@import url('https://unpkg.com/papercss/dist/paper.min.css');

@layer external {
  /* Unfortunately this doesn't work for external imports */
}

Environment

Operating System:
  Platform: darwin
  Arch: arm64
Binaries:
  Node: 20.x
  pnpm: 10.18.2
Relevant Packages:
  next: 15.5.6
  react: 19.2.0
  react-dom: 19.2.0

Additional Context

This affects any Next.js project trying to use modern CSS cascade layers with external stylesheets. The CSS Cascade 5 spec explicitly supports this syntax:

@import <url> [layer | layer(<layer-name>)]? <media-query-list>?;

Related

extent analysis

TL;DR

Disable Turbopack for development or wait for the upstream Lightning CSS bug to be fixed to preserve layer() and media query attributes in @import statements.

Guidance

  • To immediately mitigate the issue, remove the --turbopack flag from the dev script in package.json to fall back to Webpack for development.
  • Monitor the upstream Lightning CSS issue (https://github.com/parcel-bundler/lightningcss/issues/1074) for a fix that will allow Turbopack to correctly preserve layer() attributes.
  • Consider using @layer blocks instead of import attributes for internal styles, but note this does not work for external imports.
  • Verify the fix by checking the browser dev tools for the presence of layer() and media query attributes in @import statements after making changes.

Example

To disable Turbopack, update package.json as follows:

{
  "scripts": {
    "dev": "next dev"
  }
}

Notes

This workaround only addresses development mode and does not fix the underlying issue with Turbopack and Lightning CSS. Production builds with Webpack are not affected.

Recommendation

Apply the workaround by disabling Turbopack for development until the upstream Lightning CSS bug is fixed, as this allows for consistent behavior with production builds and preserves the desired CSS attributes.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING