Repository navigation
fix(core,cli): fix Node.js ESM resolution for CLI theme build - #2512
Merged
Merged
Conversation
imdreamrunner
requested review from
cixzhang,
czarandy and
josephfarina
as code owners
June 4, 2026 00:08
|
@imdreamrunner must be a member of the Meta Open Source team on Vercel to deploy. Learn more about collaboration on Vercel and other options here. |
Contributor
🚀 Vercel Preview Deployment
|
Contributor
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR No new or modified components detected. Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
imdreamrunner
marked this pull request as draft
June 4, 2026 00:22
cixzhang
approved these changes
Jun 4, 2026
imdreamrunner
force-pushed
the
fix/esm-cli-compat
branch
from
June 4, 2026 00:54
08df8de to
46ec654
Compare
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
#2472 made @xds/core ESM-only ("type": "module"), which broke the CLI's build-theme.mjs. require() fails on ESM-only packages, and the empty catch {} silently swallowed the error, causing generateThemeRulesSplit to be null. Theme generation fell back to a buggy code path that emitted prose heading resets into @layer xds-theme instead of @layer reset, breaking display-1 headings (42px → 24px). Fixes: - Add babel-plugin-add-extensions.cjs to rewrite extensionless relative imports with .js extensions during Babel compilation. Handles both file imports ('./XDSButton' → './XDSButton.js') and directory imports ('./domainTokens' → './domainTokens/index.js'). This replaces the postbuild-add-extensions.mjs script with a proper Babel plugin. - Switch build-theme.mjs from require() to dynamic import() and surface errors instead of silently swallowing them.
imdreamrunner
force-pushed
the
fix/esm-cli-compat
branch
from
June 4, 2026 01:33
46ec654 to
5218e42
Compare
imdreamrunner
marked this pull request as ready for review
June 4, 2026 03:48
7 tasks done
cixzhang
pushed a commit
that referenced
this pull request
Jun 21, 2026
#2472 made @xds/core ESM-only ("type": "module"), which broke the CLI's build-theme.mjs. require() fails on ESM-only packages, and the empty catch {} silently swallowed the error, causing generateThemeRulesSplit to be null. Theme generation fell back to a buggy code path that emitted prose heading resets into @layer xds-theme instead of @layer reset, breaking display-1 headings (42px → 24px). Fixes: - Add babel-plugin-add-extensions.cjs to rewrite extensionless relative imports with .js extensions during Babel compilation. Handles both file imports ('./XDSButton' → './XDSButton.js') and directory imports ('./domainTokens' → './domainTokens/index.js'). This replaces the postbuild-add-extensions.mjs script with a proper Babel plugin. - Switch build-theme.mjs from require() to dynamic import() and surface errors instead of silently swallowing them.
cixzhang
pushed a commit
that referenced
this pull request
Jun 21, 2026
#2472 made @xds/core ESM-only ("type": "module"), which broke the CLI's build-theme.mjs. require() fails on ESM-only packages, and the empty catch {} silently swallowed the error, causing generateThemeRulesSplit to be null. Theme generation fell back to a buggy code path that emitted prose heading resets into @layer xds-theme instead of @layer reset, breaking display-1 headings (42px → 24px). Fixes: - Add babel-plugin-add-extensions.cjs to rewrite extensionless relative imports with .js extensions during Babel compilation. Handles both file imports ('./XDSButton' → './XDSButton.js') and directory imports ('./domainTokens' → './domainTokens/index.js'). This replaces the postbuild-add-extensions.mjs script with a proper Babel plugin. - Switch build-theme.mjs from require() to dynamic import() and surface errors instead of silently swallowing them.
This branch had an error being deployed
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.
Problem
#2472 made
@xds/coreESM-only ("type": "module"), which broke the CLI'stheme buildcommand. The causal chain:build-theme.mjsusedrequire('@xds/core/theme')to load theme generation utilitiesrequire()fails on ESM-only packages →ERR_MODULE_NOT_FOUNDcatch {}silently swallowed the error →generateThemeRulesSplit = null@layer xds-themeinstead of@layer reset@layer xds-themeoutranks@layer xds-base, so the bareh1 { font-size: 24px }rule overrides StyleX'sdisplay-1class → headings collapse to 24pxFix
require()toawait import()inbuild-theme.mjs— the file is already.mjs, so dynamicimport()is the natural ESM approachcatch (e) { console.warn(...) }instead ofcatch {}postbuild-add-extensions.mjs— Babel CLI preserves extensionless imports from TypeScript source (e.g.'./XDSButton'). Bundlers resolve these fine, but Node.js native ESM requires explicit extensions for"type": "module"packages. This script rewrites them to'./XDSButton.js'after the build.Test plan
pnpm buildsucceeds with extension rewriting (340 of 447 files)xds theme buildloads@xds/core/themewithout warningsastryx.csshas prose resets in@layer reset(not@layer xds-theme)h1rules in@layer xds-theme(confirmed viaawkgrep)display-1StyleX class overridden byh1reset in wrong@layer xds-theme@layer reset, StyleXdisplay-1class wins