Open leonard-henriquez opened 1 year ago
After hours (and hours) of debugging, I finally understood that if we use emitDecoratorMetadata: true
in our tsconfig.json
SWC is used instead of esbuild.
In this case it seems that some configuration options from the tsconfig.json are not picked up (such as compilerOptions.jsx
). .swcrc
files do not seem to be used either.
@egoist , do you know how can I specify a JSX runtime if I have emitDecoratorMetadata set to true
?
PS: It is written somewhere in the documentation (in the troubleshooting section) but the fact that changing emitDecoratorMetadata
to true has the side effect of changing the build system is quite surprising. I think I would be more appropriate to have an actual TSup setting to choose which build system we want (with only SWC being available if you want to use emitDecoratorMetadata)
Not sure if this helps at all, but I had a similar issue with a Design System that's bundled with tsup.
The consumer was throwing the error ReferenceError: React is not defined
and sure enough, the compiled DS code had React.createElement
with no React
definition.
I changed compilerOptions.jsx
in tsconfig.json
to "react-jsx"
as that property allegedly remaps all React.createElement
calls to _jsx
calls.
Seems to work now. Will let you know if something blows up later unintentionally 😅
We got the same error in shopify/hydrogen. We were compiling with compilerOptions.jsx: preserve
(tsconfig here) just fine using tsup@6.5 (example).
However, after updating to tsup@7.2.0, it started ignoring "preserve" and compile JSX to React.createElement
without importing React in the files (example).
Changing the tsconfig to use compilerOptions.jsx: react-jsx
fixes the issue for us.
Adding "react-jsx"
to the compiler options adds "react/jsx-runtime"
as a hard dependency to your bundle.
I solved it using "preserve"
in the compilerOptions + adding import React from 'react'
to my files
To build js you don't have tsconfig.json
and you have to add this to tsup.config.js
to not get the error "React is not defined":
esbuildOptions(options) {
options.jsx = 'automatic';
},
I wanted to switch from SWC to TSup to reduce the complexity of my configuration.
From what I've read in ESbuild documentation and TSup changelog, I expected TSup to automatically pickup my JSX config from
tsconfig.json
settings.However, when I tried to install TSup, I got the error
React is not defined
(see the configuration below). Besides, when I look at the generated file, I notice thatReact.createElement
is used whileReact
is never defined.Configuration:
Related issues:
PS: I succeeded to make it work by injecting React as mentioned in the related issues but the solution is not
Upvote & Fund