CSS import order differs between dev turbopack and prod webpack
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- css, javascript, next.js, typescript, webpack
- Domain
- build-system, frontend
Research direction
Start by cloning the linked reproduction and running pnpm docs:dev, then pnpm docs:build and pnpm docs:start to compare the CSS layer order at /preview-card. Read docs/src/app/layout.tsx, reset.css, ThemeToggle.module.css, and test-package/index.css. Done means development and production preserve the declared CSS layer order.
Written by the indexing model from the issue text.
Description
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
git clone https://github.com/brijeshb42/nextjs-css-order-repro.gitpnpm install
Dev mode
pnpm docs:devwill start the docs in dev mode (with Turbopack enabled). Open the URL http://localhost:3000/preview-card and you'll see that theSize 1,Size 2etc text is underlined and has a color.- Right click on the
Size 1text and gotoInspectto inspect the element in devtools. On the right, you'll seetext-decoration-lineandcolorproperties applied with relevant values. Clicking the Layercomponentswill show the layer order astheme,base,components,utilitiesandtokens.
Prod mode
pnpm docs:buildwill build the app with Webpack.pnpm docs:startwill start the built app. Goto the same url http://localhost:3000/preview-card. You'll see that theSize 1,Size 2etc text now not underlined and the color is black.- Right click on the
Size 1text and gotoInspectto inspect the element in devtools. On the right, clicking the Layerbasewill show the layer order astokens,components,theme,baseandutilities.
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
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
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
- Dominant language
- JavaScript
- Stars
- 142k
- Forks
- 32.5k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 334
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from vercel/next.js
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Image (next/image)
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Loading UI and Streaming
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Similar issues
-
code-quality refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
optimization optimization:agents-md-curator
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
githubnext/gh-aw-cao#13143 ·
-
status: needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100