evanw / evanw/esbuild

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

Open
#4,074 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
40.1k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

Reproduction

![Image](https://github.com/user-attachments/assets/965a8df0-6287-45cd-b9d3-315cb1fa41c4)

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.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the StackBlitz reproduction and inspect how plugin-loaded TSX or JSX differs from natively loaded JSX when resolveDir is provided. Trace the build and transform entry points involved in tsconfig lookup and plugin virtual modules. Done means a virtual TSX module can inherit the relevant JSX compilerOptions from its importer without requiring the plugin to resolve and transform them manually.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
build-system, compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.