From 23f6d5492c3c47b2011a4437dacff2b4beaf7028 Mon Sep 17 00:00:00 2001 From: Jack Hsu Date: Mon, 9 May 2022 12:32:08 -0400 Subject: [PATCH] fix(react): SWC compiled code should include react jsx runtime (#10220) Fixes #8869 --- e2e/web/src/web.test.ts | 5 +++++ packages/web/src/executors/rollup/lib/swc-plugin.ts | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/e2e/web/src/web.test.ts b/e2e/web/src/web.test.ts index 2a8d801273dc2..3875af3079278 100644 --- a/e2e/web/src/web.test.ts +++ b/e2e/web/src/web.test.ts @@ -93,6 +93,11 @@ describe('Web Components Applications', () => { ); checkFilesExist(`dist/apps/_should_not_remove.txt`); + // Asset that React runtime is imported + expect(readFile(`dist/libs/${libName}/index.esm.js`)).toMatch( + /react\/jsx-runtime/ + ); + // `delete-output-path` createFile(`dist/apps/${appName}/_should_keep.txt`); runCLI(`build ${appName} --delete-output-path=false --outputHashing none`); diff --git a/packages/web/src/executors/rollup/lib/swc-plugin.ts b/packages/web/src/executors/rollup/lib/swc-plugin.ts index 3c70e40740187..36eb86386929a 100644 --- a/packages/web/src/executors/rollup/lib/swc-plugin.ts +++ b/packages/web/src/executors/rollup/lib/swc-plugin.ts @@ -7,6 +7,11 @@ export function swc(): Plugin { transform(code, filename) { return transform(code, { filename, + jsc: { + transform: { + react: { runtime: 'automatic' }, + }, + }, }); }, };