Skip to content

Commit 5771eb3

Browse files
Coly010jaysoo
authored andcommitted
fix(react-native): use vite's transformWithEsbuild instead of direct esbuild import
The react-native vite config template imported esbuild directly, which fails during project graph processing in pnpm strict mode because esbuild is only a transitive dependency of vite and not hoisted to root node_modules. Fixes e2e-detox:e2e-macos-local failure.
1 parent 070ca28 commit 5771eb3

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

packages/react-native/src/generators/web-configuration/files/base-vite/vite.config.mts__tmpl__

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { defineConfig } from 'vite';
1+
import { defineConfig, transformWithEsbuild } from 'vite';
22
import react from '@vitejs/plugin-react';
33
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
4-
import * as esbuild from 'esbuild';
54
import { readFileSync } from 'fs';
65

76
const extensions = [
@@ -20,10 +19,13 @@ const extensions = [
2019

2120
const rollupPlugin = (matchers: RegExp[]) => ({
2221
name: 'js-in-jsx',
23-
load(id: string) {
22+
async load(id: string) {
2423
if (matchers.some((matcher) => matcher.test(id)) && id.endsWith('.js')) {
2524
const file = readFileSync(id, { encoding: 'utf-8' });
26-
return esbuild.transformSync(file, { loader: 'jsx', jsx: 'automatic' });
25+
return transformWithEsbuild(file, id, {
26+
loader: 'jsx',
27+
jsx: 'automatic',
28+
});
2729
}
2830
},
2931
});
@@ -39,7 +41,8 @@ export default defineConfig({
3941
alias: {
4042
'react-native': 'react-native-web',
4143
'react-native-svg': 'react-native-svg-web',
42-
'@react-native/assets-registry/registry': 'react-native-web/dist/modules/AssetRegistry/index',
44+
'@react-native/assets-registry/registry':
45+
'react-native-web/dist/modules/AssetRegistry/index',
4346
},
4447
},
4548
build: {

0 commit comments

Comments
 (0)