playwright
playwright copied to clipboard
[BUG] Importing .tsx files does not work when using TypeScript + ESM + NodeNext
Context:
- Playwright Version: 1.25.2
- Operating System: Linux
- Node.js version: 16.17.0
- Browser: Not relevant
- Extra: TypeScript + ESM + NodeNext enabled
Code Snippet
Full reproduction available here: https://github.com/akselikap/playwright-esm-typescript-bug
Describe the bug
.tsx -files cannot be imported in tests if ESM is used with the configuration provided in the repository. It leads to this error: Error: Cannot find module '/src/index.js' imported from /test/playwright/test.spec.ts
You can test this with the provided repository by running npm run test
. Then you can delete/rename the test.spec.ts file and run the command again to see that it works when not using .tsx imports.
Workaround Only type imports work from .tsx files. Fortunately that was enough for me.
Playwright only supports TSX when testing components and it will only import components from those TSX files.
Let me keep it open to ensure sufficient docs explaining why and how to work around.
Ahh, that makes sense. Too bad our code has pretty random import chains and the code base is old enough that type imports were not a thing back then. Thanks for the quick response!
Also need to update #14298 and merge it into docs.