Skip to content

fix(css): emit require() for injected CSS in CJS output - #1136

Merged
sxzz merged 3 commits into
rolldown:mainfrom
MFA-G:fix/css-inject-cjs-require
Nov 19, 2026
Merged

sxzz merged 3 commits into
rolldown:mainfrom
MFA-G:fix/css-inject-cjs-require

Conversation

@MFA-G

@MFA-G MFA-G commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

AI usage

  • No AI was used in this PR.
  • AI was used: Hermes Agent + DeepSeek V4.1 Flash
    • I have carefully reviewed the AI-generated content myself.

Description

css.inject always prepended an ESM import '...' statement, so CJS chunks got import './style.css'; — invalid CommonJS. The injected statement now follows the output format: require('...') for CJS and the previous import '...' for ESM.

The same problem existed for the shared CSS-only chunk rewrite in splitting mode: the regex only matched import '...', so in CJS a chunk kept require('./shared-xxx.cjs') for a chunk that is later removed, and the emitted CSS asset was never referenced. That require is now rewritten to the .css file as well.

Linked Issues

Fixes #1135

Additional context

Validation:

  • pnpm vitest run — 37 files, 564 passed, 4 expected fail, 4 skipped
  • pnpm typecheck
  • pnpm exec eslint packages/css/src/plugin.ts tests/css.test.ts
  • pnpm exec prettier --check packages/css/src/plugin.ts tests/css.test.ts

Two regression tests were added under css.inject: a plain CJS entry and a CJS build with splitting: true that reuses a shared CSS-only chunk. Both fail on main and pass with this change.

Copilot AI balanced review requested due to automatic review settings November 18, 2026 13:18
@netlify

netlify Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

👷 Deploy request for tsdown-main pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit af3bf54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@pkg-pr-new

pkg-pr-new Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

tsdown

pnpm add https://pkg.pr.new/rolldown/tsdown@1136 -D
npm i https://pkg.pr.new/rolldown/tsdown@1136 -D
yarn add https://pkg.pr.new/rolldown/tsdown@1136.tgz -D

create-tsdown

pnpm add https://pkg.pr.new/rolldown/tsdown/create-tsdown@1136 -D
npm i https://pkg.pr.new/rolldown/tsdown/create-tsdown@1136 -D
yarn add https://pkg.pr.new/rolldown/tsdown/create-tsdown@1136.tgz -D

@tsdown/css

pnpm add https://pkg.pr.new/rolldown/tsdown/@tsdown/css@1136 -D
npm i https://pkg.pr.new/rolldown/tsdown/@tsdown/css@1136 -D
yarn add https://pkg.pr.new/rolldown/tsdown/@tsdown/css@1136.tgz -D

@tsdown/exe

pnpm add https://pkg.pr.new/rolldown/tsdown/@tsdown/exe@1136 -D
npm i https://pkg.pr.new/rolldown/tsdown/@tsdown/exe@1136 -D
yarn add https://pkg.pr.new/rolldown/tsdown/@tsdown/exe@1136.tgz -D

tsdown-migrate

pnpm add https://pkg.pr.new/rolldown/tsdown/tsdown-migrate@1136 -D
npm i https://pkg.pr.new/rolldown/tsdown/tsdown-migrate@1136 -D
yarn add https://pkg.pr.new/rolldown/tsdown/tsdown-migrate@1136.tgz -D

commit: af3bf54

@sxzz
sxzz enabled auto-merge (squash) November 19, 2026 05:48
@sxzz
sxzz merged commit 5b88c34 into rolldown:main Nov 19, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

css.inject adds import './style.css'; to CJS builds

4 participants