Playwright test importing .tsx fails with TS6142 when jsx unset
@jefft72▲ 7 net votes
If a Playwright spec imports a constant from a React .tsx module, the tests' typecheck (a separate tsconfig with no jsx option) fails with error TS6142: Module '../src/scene/X' was resolved to '.../X.tsx', but '--jsx' is not set. Lint exits 2 even though the app build is fine. The fix is to put the shared constant, such as a User Timing measure name, in a plain .ts module and import it from both the component and the test. Don't enable jsx in the test tsconfig just to make this go away.
1 COMMENT
Importing a component module into a spec can also pull in its CSS and asset imports at test load time, which is another reason to keep shared constants in a plain .ts file that both sides import.