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 preserve does not work #18168

Closed
7 tasks done
DavidVollmers opened this issue Sep 22, 2024 · 4 comments
Closed
7 tasks done

jsx preserve does not work #18168

DavidVollmers opened this issue Sep 22, 2024 · 4 comments

Comments

@DavidVollmers
Copy link

DavidVollmers commented Sep 22, 2024

Describe the bug

I am trying to build a library containing tsx files to ouput jsx files. As I understand this is done by setting the jsx config in tsconfig.json to preserve. For some reason I cannot make this work and it will always output a js file using React.createElement.

Reproduction

https://github.com/DavidVollmers/vite-jsx-lib

Steps to reproduce

Run npm i and then nx build and look into the dist folder. It will contain only a lib/index.js files and no lib/index.jsx file. Also in the lib/index.js file you will see the following output generated:

const t = /* @__PURE__ */ React.createElement("button", null);
export {
  t as jsx
};

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (28) x64 13th Gen Intel(R) Core(TM) i7-13850HX
    Memory: 15.57 GB / 31.69 GB
  Binaries:
    Node: 20.16.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.8.1 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (128.0.2739.63)
    Internet Explorer: 11.0.19041.4355

Used Package Manager

npm

Logs

No response

Validations

@DavidVollmers DavidVollmers changed the title jsx preserved does not work jsx preserve does not work Sep 22, 2024
@hi-ogawa
Copy link
Collaborator

Preserving jsx for build is likely not supported. For one, it looks like rollup requires a parser plugin to do that rollup/rollup#4431 but with some caveat. Even if that works on rollup, Vite's transform pipeline expects plain js (for example, es-module-lexer used during vite:build-import-analysis's transform), so jsx needs to be transpiled away earlier.

@DavidVollmers
Copy link
Author

Any confirmation that this is not supported and maybe some hints on how to get around this? In theory I could produce the jsx files using tsc but this gets more complicated in larger mono repositories...

@hi-ogawa
Copy link
Collaborator

hi-ogawa commented Sep 23, 2024

I tried to follow rollup/rollup#4431 but it turned out acornInjectPlugin option has been already removed in rollup 4 https://rollupjs.org/migration/#configuration-changes

This means, unfortunately, that you can no longer add plugins for unsupported syntax. Depending on demand, we consider supporting JSX syntax again as the SWC parser would support that.

(On Vite side, you could set esbuild.jsx: "preserve" and also patch out vite:build-import-analysis plugin, but rollup would be a final blocker.)

@DavidVollmers
Copy link
Author

OK I see, thank you. At least setting esbuild.jsx: "preserve" did not do anything for me. I will try to come up with a workaround (probably by not using vite anymore 😢)...

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

No branches or pull requests

2 participants