Skip to content

CSS import order differs between dev turbopack and prod webpack #79531

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
brijeshb42 opened this issue May 23, 2025 · 0 comments
Open

CSS import order differs between dev turbopack and prod webpack #79531

brijeshb42 opened this issue May 23, 2025 · 0 comments
Labels
Turbopack Related to Turbopack with Next.js. Webpack Related to Webpack with Next.js.

Comments

@brijeshb42
Copy link

brijeshb42 commented May 23, 2025

Link to the code that reproduces this issue

https://github.com/brijeshb42/nextjs-css-order-repro

To Reproduce

TLDR: The import order of css files changes between dev (with Turbpack) and prod (without Turbopack).

Setup

  1. git clone https://github.com/brijeshb42/nextjs-css-order-repro.git
  2. pnpm install

Dev mode

  1. pnpm docs:dev will start the docs in dev mode (with Turbopack enabled). Open the URL http://localhost:3000/preview-card and you'll see that the Size 1, Size 2 etc text is underlined and has a color.
  2. Right click on the Size 1 text and goto Inspect to inspect the element in devtools. On the right, you'll see text-decoration-line and color properties applied with relevant values. Clicking the Layer components will show the layer order as theme, base, components, utilities and tokens.
Image Image

Prod mode

  1. pnpm docs:build will build the app with Webpack.
  2. pnpm docs:start will start the built app. Goto the same url http://localhost:3000/preview-card. You'll see that the Size 1, Size 2 etc text now not underlined and the color is black.
  3. Right click on the Size 1 text and goto Inspect to inspect the element in devtools. On the right, clicking the Layer base will show the layer order as tokens, components, theme, base and utilities.
Image Image

Issue

In dev mode, the css order is as expected, which is declared in docs/src/app/layout.tsx. First test-package/index.css is imported which has an explicit layer order defined and then local ./reset.css is imported.

In prod mode, its not the same case. Looking at the built files in browser, the order is

  1. ./reset.css
  2. ThemeToggle.module.css

and test-package/index.css seems to be imported at the end. So the css layer order gets defined implicitly as and when components get imported.

Current vs. Expected behavior

In dev mode, the css order is as expected, which is declared in docs/src/app/layout.tsx. First test-package/index.css is imported which has an explicit layer order defined and then local ./reset.css is imported.

In prod mode, its not the same case. Looking at the built files in browser, the order is

  1. ./reset.css
  2. ThemeToggle.module.css

and test-package/index.css seems to be imported at the end. So the css layer order gets defined implicitly as and when components get imported.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.5.0: Tue Apr 22 19:52:00 PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T6031
  Available memory (MB): 36864
  Available CPU cores: 14
Binaries:
  Node: 20.17.0
  npm: 11.0.0
  Yarn: N/A
  pnpm: 10.7.0
Relevant Packages:
  next: 15.4.0-canary.48 // Latest available version is detected (15.4.0-canary.48).
  eslint-config-next: N/A
  react: 19.1.0
  react-dom: 19.1.0
  typescript: 5.8.3
Next.js Config:
  output: export

Which area(s) are affected? (Select all that apply)

Turbopack, Webpack

Which stage(s) are affected? (Select all that apply)

next build (local)

Additional context

No response

@github-actions github-actions bot added Turbopack Related to Turbopack with Next.js. Webpack Related to Webpack with Next.js. labels May 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Turbopack Related to Turbopack with Next.js. Webpack Related to Webpack with Next.js.
Projects
None yet
Development

No branches or pull requests

1 participant