-
-
Notifications
You must be signed in to change notification settings - Fork 59
Open
Description
Version
### 📝 **Environment**
- **@rslib/core**: 0.14.0
- **@rsbuild/core**: 1.5.12
- **Node.js**: Latest
- **Browser**: Any modern browser
Details
Issue Description:
🐛 Bug Report
rslib v0.14.0 generates CommonJS module.id
references in ESM output when using injectStyles: true
with CSS containing @font-face
declarations, causing runtime errors in browsers.
🎯 Root Cause
The issue occurs when ALL these conditions are met:
- ✅
injectStyles: true
in rslib config - ✅
format: "esm"
(ESM output format) - ✅
@font-face
declarations in imported CSS files - ✅ Any export from the module that imports the CSS
Key Finding: Not React-specific - any export from a module importing CSS with @font-face
triggers the issue.
💥 Runtime Error
Uncaught ReferenceError: module is not defined
at http://localhost:4173/assets/index-[hash].js:321:2408
📋 Minimal Reproduction
Repository: https://github.com/sub-ld/rslib-inject-styles-bug
Minimal files that trigger the issue:
// src/index.ts
import "./globals.css";
export const foo = "bar"; // ANY export triggers the issue
/* src/globals.css */
@font-face {
font-family: "TestFont";
src: url("data:font/woff2;base64,") format("woff2");
}
🐛 Problematic Generated Code
The built ESM library contains:
___CSS_LOADER_EXPORT___.push([
module.id, // ← CommonJS artifact in ESM bundle!
`@font-face { font-family: "TestFont"; ... }`,
]);
🧪 Test Results
CSS Import | Export | module.id Count |
Runtime Result |
---|---|---|---|
None | Yes | 0 | ✅ Works |
@font-face | None | 1 | |
@font-face | Yes | 1 | ❌ Runtime Error |
🎯 Expected Behavior
ESM libraries with injectStyles: true
should:
- Not generate CommonJS artifacts like
module.id
- Properly transform CSS loader output for ESM compatibility
- Work seamlessly with
@font-face
declarations
📁 Additional Resources
- Full reproduction repo: https://github.com/sub-ld/rslib-inject-styles-bug
- Detailed technical analysis: ISSUE_DETAILS.md
- Minimal reproduction case: README.md
Reproduce link
https://github.com/sub-ld/rslib-inject-styles-bug
Reproduce Steps
git clone https://github.com/sub-ld/rslib-inject-styles-bug
cd rslib-inject-styles-bug
npm install
npm run build
npm run build:consumer
grep "module.id" dist/index.js # Shows CommonJS artifacts in ESM bundle
npm run build:consumer && npm run preview # Runtime error in browser
Metadata
Metadata
Assignees
Labels
No labels