Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(build): compile dist with the production JSX transform (#3930)

wang293d881be66ea
diff --git a/.changeset/plain-hoops-repeat.md b/.changeset/plain-hoops-repeat.md
new file mode 100644
index 0000000000..8ba306ef8f
--- /dev/null
+++ b/.changeset/plain-hoops-repeat.md
@@ -0,0 +1,18 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] Compile dist with the production JSX transform — 0.1.5 shipped `jsxDEV`, which crashes every consumer that renders in production
+@fatwang2
+
+`@babel/preset-react` 8 derives its `development` option from the Babel env name
+(`api.env(env => env === 'development')`), and Babel falls back to
+`"development"` whenever `NODE_ENV`/`BABEL_ENV` is unset. The bump from 7.29.7 to
+8.0.1 therefore flipped the published build to the development JSX transform
+without any config change: 193 of 479 files in `@astryxdesign/[email protected]`'s
+`dist` import `react/jsx-dev-runtime` and call `jsxDEV`, which React's
+production build does not export.
+
+The Babel configs for core, lab, and charts now pin `development: false`, and a
+new `scripts/check-no-dev-jsx.mjs` guard fails the build if development JSX ever
+reaches `dist` again.
diff --git a/packages/charts/babel.config.js b/packages/charts/babel.config.js
index 71be1f8126..149808a0cb 100644
--- a/packages/charts/babel.config.js
+++ b/packages/charts/babel.config.js
@@ -23,7 +23,7 @@ const rootDir = path.resolve(__dirname, '../..');
module.exports = {
presets: [
- ['@babel/preset-react', {runtime: 'automatic'}],
+ ['@babel/preset-react', {runtime: 'automatic', development: false}],
['@babel/preset-typescript', {isTSX: true, allExtensions: true}],
],
plugins: [
diff --git a/packages/charts/package.json b/packages/charts/package.json
index bf01f61e2c..7cc0c00b55 100644
--- a/packages/charts/package.json
+++ b/packages/charts/package.json
@@ -46,7 +46,7 @@
},
"scripts": {
"prepack": "pnpm build",
- "build": "rm -rf dist && pnpm build:esm && tsc --project tsconfig.build.json && pnpm build:css",
+ "build": "rm -rf dist && pnpm build:esm && tsc --project tsconfig.build.json && pnpm build:css && node ../../scripts/check-no-dev-jsx.mjs",
"build:esm": "babel src --out-dir dist --extensions '.ts,.tsx' --out-file-extension '.js' --ignore '**/*.test.ts,**/*.test.tsx,**/__tests__/**,**/*.perf.test.*,**/*.doc.mjs,**/*.d.ts,**/*.css,**/*.css.d.ts' --config-file ./babel.config.js",
"build:css": "node ../../scripts/build-css.mjs --package charts",
"dev": "babel src --watch --out-dir dist --extensions '.ts,.tsx' --out-file-extension '.js' --ignore '**/*.test.*,**/*.doc.mjs,**/*.d.ts,**/*.css*' --config-file ./babel.config.js",
diff --git a/packages/core/babel.config.json b/packages/core/babel.config.json
index b1c7a25273..bb109db361 100644
--- a/packages/core/babel.config.json
+++ b/packages/core/babel.config.json
@@ -1,6 +1,6 @@
{
"presets": [
- ["@babel/preset-react", {"runtime": "automatic"}],
+ ["@babel/preset-react", {"runtime": "automatic", "development": false}],
["@babel/preset-typescript", {"isTSX": true, "allExtensions": true}]
],
"plugins": [
diff --git a/packages/core/package.json b/packages/core/package.json
index 394128c9e9..206e6533c8 100644
--- a/packages/core/package.json
+++ b/packages/core/package.json
@@ -627,7 +627,7 @@
],
"scripts": {
"prepack": "pnpm build",
- "build": "rimraf dist && pnpm build:esm && tsc --project tsconfig.build.json && pnpm build:css && pnpm build:umd",
+ "build": "rimraf dist && pnpm build:esm && tsc --project tsconfig.build.json && pnpm build:css && pnpm build:umd && node ../../scripts/check-no-dev-jsx.mjs",
"build:esm": "babel src --out-dir dist --extensions .ts,.tsx --out-file-extension .js --ignore \"**/*.test.ts,**/*.test.tsx,**/__tests__/**,**/*.perf.test.*,**/*.doc.mjs,**/*.d.ts,**/*.css,**/*.css.d.ts\" --config-file ./babel.config.json",
"build:css": "node ../../scripts/build-css.mjs",
"build:umd": "node ../../scripts/build-umd.mjs",
diff --git a/packages/lab/babel.config.js b/packages/lab/babel.config.js
index 305dc513ba..31cedcd53b 100644
--- a/packages/lab/babel.config.js
+++ b/packages/lab/babel.config.js
@@ -23,7 +23,7 @@ const rootDir = path.resolve(__dirname, '../..');
module.exports = {
presets: [
- ['@babel/preset-react', {runtime: 'automatic'}],
+ ['@babel/preset-react', {runtime: 'automatic', development: false}],
['@babel/preset-typescript', {isTSX: true, allExtensions: true}],
],
plugins: [
diff --git a/packages/lab/package.json b/packages/lab/package.json
index 5029aa454a..e528233fcf 100644
--- a/packages/lab/package.json
+++ b/packages/lab/package.json
@@ -46,7 +46,7 @@
},
"scripts": {
"prepack": "pnpm build",
- "build": "rm -rf dist && pnpm build:esm && tsc --project tsconfig.build.json && pnpm build:css",
+ "build": "rm -rf dist && pnpm build:esm && tsc --project tsconfig.build.json && pnpm build:css && node ../../scripts/check-no-dev-jsx.mjs",
"build:esm": "babel src --out-dir dist --extensions '.ts,.tsx' --out-file-extension '.js' --ignore '**/*.test.ts,**/*.test.tsx,**/__tests__/**,**/*.perf.test.*,**/*.doc.mjs,**/*.d.ts,**/*.css,**/*.css.d.ts' --config-file ./babel.config.js",
"build:css": "node ../../scripts/build-css.mjs --package lab",
"dev": "babel src --watch --out-dir dist --extensions '.ts,.tsx' --out-file-extension '.js' --ignore '**/*.test.*,**/*.doc.mjs,**/*.d.ts,**/*.css*' --config-file ./babel.config.js",
diff --git a/scripts/check-no-dev-jsx.mjs b/scripts/check-no-dev-jsx.mjs
new file mode 100644
index 0000000000..a8b386380e
--- /dev/null
+++ b/scripts/check-no-dev-jsx.mjs
@@ -0,0 +1,83 @@
+#!/usr/bin/env node
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * Build-output check: verify the compiled dist contains no development JSX.
+ *
+ * React's production build does not export `jsxDEV` — `react/jsx-dev-runtime`
+ * resolves it to `undefined`. A dist compiled with the development JSX
+ * transform therefore throws `TypeError: jsxDEV is not a function` the moment
+ * a consumer server-renders (or client-renders in production) any component.
+ *
+ * @babel/preset-react 8 defaults `development` to `api.env(env => env ===
+ * 'development')`, and Babel's env name falls back to "development" whenever
+ * NODE_ENV/BABEL_ENV is unset — so an ambient env var is all that stands
+ * between a release build and a broken package. The configs pin
+ * `development: false`; this guard makes sure nothing silently unpins it.
+ *
+ * Usage: node ../../scripts/check-no-dev-jsx.mjs (run from a package root,
+ * after the package's dist has been built)
+ */
+import fs from 'node:fs';
+import path from 'node:path';
+
+const DIST_DIR = path.resolve(process.cwd(), 'dist');
+
+const PATTERNS = [
+ {pattern: 'react/jsx-dev-runtime', label: 'imports react/jsx-dev-runtime'},
+ {pattern: 'jsxDEV', label: 'calls jsxDEV'},
+];
+
+function walk(dir) {
+ const results = [];
+ for (const entry of fs.readdirSync(dir, {withFileTypes: true})) {
+ const full = path.join(dir, entry.name);
+ if (entry.isDirectory()) {
+ results.push(...walk(full));
+ } else if (/\.(js|mjs|cjs)$/.test(entry.name)) {
+ results.push(full);
+ }
+ }
+ return results;
+}
+
+if (!fs.existsSync(DIST_DIR)) {
+ console.error(`❌ No dist directory at ${DIST_DIR} — build before checking.`);
+ process.exit(1);
+}
+
+const files = walk(DIST_DIR);
+const offenders = [];
+
+for (const file of files) {
+ const content = fs.readFileSync(file, 'utf-8');
+ const hits = PATTERNS.filter(({pattern}) => content.includes(pattern));
+ if (hits.length > 0) {
+ offenders.push({
+ file: path.relative(DIST_DIR, file),
+ issues: hits.map(({label}) => label),
+ });
+ }
+}
+
+if (offenders.length > 0) {
+ console.error('❌ Development JSX found in build output:\n');
+ for (const {file, issues} of offenders.slice(0, 20)) {
+ console.error(` dist/${file}: ${issues.join(', ')}`);
+ }
+ if (offenders.length > 20) {
+ console.error(` …and ${offenders.length - 20} more file(s).`);
+ }
+ console.error(
+ `\n${offenders.length} file(s) compiled with the development JSX transform. ` +
+ 'React\'s production build does not export jsxDEV, so this dist crashes ' +
+ 'every consumer that renders it in production.\n' +
+ 'Fix: keep `development: false` in the package\'s @babel/preset-react ' +
+ 'options (preset-react 8 otherwise derives it from NODE_ENV).',
+ );
+ process.exit(1);
+}
+
+console.log(
+ `✅ ${files.length} dist file(s) checked — no development JSX in build output.`,
+);