Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSX loaded by plugins is not transformed using the same settings as natively loaded JSX #4074

Open
lilnasy opened this issue Feb 12, 2025 · 0 comments

Comments

@lilnasy
Copy link

lilnasy commented Feb 12, 2025

Reproduction

Image

https://stackblitz.com/edit/node-y5qbrynb?file=index.tsx

esbuild determines "jsx" and "jsxImportSource" settings from the options provided to build() and the tsconfig.json file nearest to the source file, with the tsconfig having a higher precedence, and the explicitly provided options used as the fallback.

When a tsx or jsx file is loaded by a plugin, however, the tsconfig is not looked up. This puts the plugin in an awkward position as it must determine the project's JSX settings on its own and manually transform the JSX into JS to provide it to the "js" loader.

This may appear as expected behavior since esbuild needs to know where to look for the tsconfig file and a disk location doesnt make sense for a virtual module. However, it remains an issue even when a resolveDir is provided, which should be a sufficient hint.

If resolveDir is not appropriate for tsconfig lookup, esbuild could alternatively provide the resolved and parsed options so that the plugin can use them to call esbuild.transform with the appropriate settings. Either way, the goal is to allow a virtual TSX module to "inherit" the compilerOptions of its importer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant