Repository navigation
fix(bundle): emit CSSStyleSheet for CSS raw imports - #35598
Merged
Merged
Conversation
A `with { type: "css" }` import evaluates to a constructable
`CSSStyleSheet` at runtime, but `deno bundle` routed the CSS source
through esbuild's CSS loader, leaving the default import as an empty
object (or failing when no output path was configured). Synthesize an
equivalent JS module that constructs the `CSSStyleSheet` instead.
Closes #35596
The bundled output uses `new CSSStyleSheet()`, but the `CSSStyleSheet` global is only exposed when `--unstable-raw-imports` is enabled, so running the bundle without the flag failed with "CSSStyleSheet is not defined".
bartlomieju
enabled auto-merge (squash)
June 29, 2026 10:39
The expected output had the CSS rule on a single line (h1 { margin: 0; }),
but CSSStyleSheet.cssRules[0].cssText serializes multi-line in Deno, both
for a direct runtime import and for the bundled output. Match the
expectation to the canonical serialization so the spec test passes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #35596.
A CSS raw import (
import sheet from "./a.css" with { type: "css" },gated behind
--unstable-raw-imports) evaluates to a constructableCSSStyleSheetat runtime via the custom module evaluation callback inruntime/worker.rs. The bundler did not mirror this: it routed the CSSsource through esbuild's builtin CSS loader, which has no notion of a
CSSStyleSheetdefault export. The result was that the default importcame back as an empty object (
var style_default = {}), and when nooutput path was configured the build failed outright with "Cannot
import into a JavaScript file without an output path configured".
esbuild has no builtin loader that produces a
CSSStyleSheet, so thissynthesizes an equivalent JS module for
with { type: "css" }importsinstead of handing the source to the CSS loader:
The CSS text is emitted as a JSON-encoded string literal so it is safely
escaped. With this change, bundling the reproduction from the issue
produces a real
CSSStyleSheet, and running the bundle logs theexpected stylesheet rather than
{}.A spec test under
tests/specs/bundle/raw_imports_cssbundles a CSSimport, deletes the source
.cssfile to prove the contents are inlinedinto the bundle, then runs the output and asserts it is a
CSSStyleSheetwith the expected rule.