diff --git a/packages/plugin-react/src/index.ts b/packages/plugin-react/src/index.ts index cd8870e94ff2f6..6d5f05aef8a32f 100644 --- a/packages/plugin-react/src/index.ts +++ b/packages/plugin-react/src/index.ts @@ -97,7 +97,6 @@ export default function viteReact(opts: Options = {}): PluginOption[] { const parserPlugins: typeof userParserPlugins = [ ...userParserPlugins, - 'jsx', 'importMeta', // This plugin is applied before esbuild transforms the code, // so we need to enable some stage 3 syntax that is supported in @@ -108,6 +107,10 @@ export default function viteReact(opts: Options = {}): PluginOption[] { 'classPrivateMethods' ] + if (!id.endsWith('.ts')) { + parserPlugins.push('jsx') + } + const isTypeScript = /\.tsx?$/.test(id) if (isTypeScript) { parserPlugins.push('typescript')