Repository navigation
Description
Reproduction link or steps
Describe the bug
With the default lightningcss transformer, a cross-file composes inside a Vue SFC <style module> block is not resolved.
The generated class map contains the bare, unhashed composed class name, and the composed file's CSS is never emitted, so the class matches nothing.
The same composes in a standalone *.module.css file works, and so does the SFC case with css.transformer: "postcss".
Reproduction
src/styles/button-reset.module.css
@layer button-reset {
.reset { border: none; background: transparent; }
}src/components/sfc.vue
<template><button :class="$style.btn">x</button></template>
<style module>
.btn { composes: reset from "../styles/button-reset.module.css"; color: red; }
</style>src/components/plain.module.css
.btn2 { composes: reset from "../styles/button-reset.module.css"; color: blue; }src/index.ts
import Sfc from "./components/sfc.vue";
import plain from "./components/plain.module.css";
export { Sfc, plain };tsdown.config.ts
import { defineConfig } from "tsdown";
import createVuePlugin from "unplugin-vue/rolldown";
export default defineConfig({
entry: { index: "src/index.ts" },
platform: "neutral",
plugins: [createVuePlugin({ isProduction: true })],
css: { transformer: "lightningcss" }, // default
});Run tsdown.
What is expected?
Expected (what transformer: "postcss" produces)
var sfc_vue_vue_type_style_index_0_lang_module_default = { "btn": "_btn_1f1fh_2 _reset_1snhi_2" };and the .reset rule is emitted.
What is actually happening?
Actual (lightningcss)
var sfc_vue_vue_type_style_index_0_lang_module_default = { "btn": "RmuJDa_btn reset" }; // ❌ "reset" unhashed
var plain_module_default = { "btn2": "kZ5uAW_btn2 o_hNsG_reset" }; // ✅The SFC's composed class is the literal reset. Only the copy reached via plain.module.css lands in style.css (.o_hNsG_reset), so the SFC button gets no reset styles.
Any additional comments?
Cause (as far as I can tell)
SFC style ids carry a ?vue&type=style… query, so they go through transformWithLightningCSS (lightningcss transform), not bundleWithLightningCSS.
In transform mode lightningcss does not load other files: a cross-file composes comes back as a reference with type: "dependency" and a specifier, which the caller has to resolve, compile and hash.
extractLightningCssModuleExports in packages/css/src/modules.ts appends only c.name for every reference and ignores type/specifier:
for (const c of value.composes) {
name += ` ${c.name}`
`extractLightningCssModuleExports` in `packages/css/src/modules.ts` appends only `c.name` for every reference and ignores `type`/`specifier`:
```ts
for (const c of value.composes) {
name += ` ${c.name}`
}So dependency references end up as their raw local name and the dependency is never added to the build.
Ideally the transform path would resolve dependency references (as Vite does) or at least fail loudly instead of emitting a class that matches nothing.
Related but different: #979 / #1115 (duplicated composed rules).
System info
- tsdown 0.23.7, @tsdown/css 0.23.7 (also reproduced on 0.23.0)
- lightningcss 1.33.0
- unplugin-vue 8.0.1, vue 3.5.45
- postcss-modules 9.0.1 (for the working
postcsscomparison) - Node 26.13.0, Linux
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Effort
Activity