Feature
CSS module imports landed in Deno via denoland/deno#35093 (behind the --unstable-raw-imports flag, towards denoland/deno#11961).
Importing a stylesheet with an import attribute now evaluates to a CSSStyleSheet, matching what Chrome and Firefox ship:
import sheet from "./styles.css" with { type: "css" };
console.log(sheet instanceof CSSStyleSheet);
for (const rule of sheet.cssRules) {
console.log(rule.cssText);
}
Dynamic imports work too:
const { default: sheet } = await import("./styles.css", {
with: { type: "css" },
});
The primary use case is running unmodified browser module graphs in Deno (SSR and testing of web components), where a CSS import currently kills module loading before any code runs.
What needs documenting
- How to enable the feature:
--unstable-raw-imports flag (and the "unstable": ["raw-imports"] field in deno.json).
- Static and dynamic
with { type: "css" } import syntax.
- The minimal
CSSStyleSheet surface that Deno implements:
cssRules — returns a frozen array of CSSRule (not a live CSSRuleList); each access creates a fresh array.
replace(text) / replaceSync(text) — top-level @import rules are dropped (matching the CSSOM constructed-stylesheet behavior).
CSSRule.cssText — verbatim text of one top-level rule.
new CSSStyleSheet() constructor (constructor options like media/disabled/baseURL are not supported).
- Important limitations to call out:
- Deno has no DOM, so a sheet can't be adopted anywhere; the implementation is backed by the raw CSS text.
cssRules uses a naive top-level rule split, not a real CSS parser/object model — methods like insertRule/deleteRule are not implemented.
- Reading a CSS file requires read permission (
--allow-read).
- Note the unstable status (API yet to be vetted; subject to change).
References
Feature
CSS module imports landed in Deno via denoland/deno#35093 (behind the
--unstable-raw-importsflag, towards denoland/deno#11961).Importing a stylesheet with an import attribute now evaluates to a
CSSStyleSheet, matching what Chrome and Firefox ship:Dynamic imports work too:
The primary use case is running unmodified browser module graphs in Deno (SSR and testing of web components), where a CSS import currently kills module loading before any code runs.
What needs documenting
--unstable-raw-importsflag (and the"unstable": ["raw-imports"]field indeno.json).with { type: "css" }import syntax.CSSStyleSheetsurface that Deno implements:cssRules— returns a frozen array ofCSSRule(not a liveCSSRuleList); each access creates a fresh array.replace(text)/replaceSync(text)— top-level@importrules are dropped (matching the CSSOM constructed-stylesheet behavior).CSSRule.cssText— verbatim text of one top-level rule.new CSSStyleSheet()constructor (constructoroptionslikemedia/disabled/baseURLare not supported).cssRulesuses a naive top-level rule split, not a real CSS parser/object model — methods likeinsertRule/deleteRuleare not implemented.--allow-read).References