-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Closed
Labels
feature-test-runnerPlaywright test specific issuesPlaywright test specific issues
Description
Context:
- Playwright Version: 1.25.1
- Operating System: MacOs
- Node.js version: v16.17.0
Code Snippet
import { test } from "@playwright/test";
test("dynamic import of ESM", async ({}) => {
const { default: getPort } = await import("get-port");
console.log(await getPort());
});Describe the bug
From the node.js docs
Dynamic import() is supported in both CommonJS and ES modules. In CommonJS modules it can be used to load ES modules.
Yet, trying to load an ESM only package like get-port with a dynamic import statement fails with the error:
Error [ERR_REQUIRE_ESM]: require() of ES Module .../node_modules/get-port/index.js from .../tests/example.spec.ts not supported.
Instead change the require of index.js in .../tests/example.spec.ts to a dynamic import() which is available in all CommonJS modules.
It's complaining I'm trying to use require to load an ESM only module, but as can be seen in the snippet, it's an import().
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
feature-test-runnerPlaywright test specific issuesPlaywright test specific issues