-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Description
Context:
- Playwright Version:
1.29.1 - Operating System:
Mac - Node.js version:
18.12.1 - Browser: All
- Extra: TypeScript 4.9.4
Reproducible Code
Here's a reproducible repo
- Checkout the code
- install the dependencies
ESM Variant
Navigate into the esm-variant directory and run npx playwright test, which yields error as in the picture below:

Since the typescript code is transpiled to ESM compatible code given that type=module is specified in the package.json, however babel is not configured with support for importAssertions.
CommonJS Variant
Navigate into commonjs-variant directory and run npx playwright, which yields no error as in the picture below:

Since the typescript code is transpiled to CommonJS compatible code given that type=commonjs is specified in the package.json.
Describe the bug
The problem is that the underlying babel used by playwright to transpile TypeScript, infers the type from the module field in the package.json from where the playwright is run. Whenever babel infers that the output type should be of type module aka ESM it then transpiles the code to esm compatible code that will not run via the current babel setup in Playwright since:
Support for the experimental syntax 'importAssertions' isn't currently enabled.
The @babel/plugin-syntax-import-assertions needs to be added to the current playwright setup.