-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Issue Description
When using @auto-browse/auto-browse
(an ESM module) with playwright-bdd
(a CommonJS module), there is a module loading conflict that causes Playwright to be loaded twice in different module systems.
Environment
- Node.js: v22.7.0
- @auto-browse/auto-browse: ^0.1.7
- playwright-bdd: ^8.4.1
- @playwright/test: ^1.55.0
Steps to Reproduce
- Create a new project with playwright-bdd
- Install @auto-browse/auto-browse
- Create a step definition file that imports from @auto-browse/auto-browse
- Run
npx bddgen
Error Message
Error: Requiring @playwright/test second time ... Error [ERR_REQUIRE_ESM]: require() of ES Module [...]/node_modules/@auto-browse/auto-browse/dist/index.js not supported. Instead change the require of index.js to a dynamic import() which is available in all CommonJS modules.
Attempted Solutions
- Using dynamic import:
let auto: any;
(async () => {
const autoBrowse = await import("@auto-browse/auto-browse");
auto = autoBrowse.auto;
})();
- Adding "type": "module" to package.json and using ES modules:
import { auto } from "@auto-browse/auto-browse";
- Using ts-node/register in playwright.config.ts:
export default defineConfig({
workers: 1,
fullyParallel: false,
require: ['ts-node/register'],
// ...
});
All these solutions result in the same error where Playwright is being loaded twice in different module systems.
Expected Behavior
The module should be able to be imported and used within playwright-bdd step definitions without causing module loading conflicts.
Impact
This issue prevents users from using @auto-browse/auto-browse with playwright-bdd, which are both valuable tools for test automation.
Possible Solutions
- Consider providing a CommonJS build of @auto-browse/auto-browse
- Add documentation about ESM compatibility and recommended workarounds
- Consider supporting dual package hazard scenarios where Playwright is loaded in both ESM and CommonJS contexts
Additional Context
This issue appears to be more prominent in Node.js v22.7.0 which has stricter module loading rules. The core issue is the incompatibility between ESM and CommonJS module systems when dealing with complex dependencies like Playwright.