Skip to content

[BUG] Unable to import module in test [ERR_REQUIRE_ESM] #13065

@grybykm

Description

@grybykm

Context:

  • Playwright Version: 1.20.1 (also tried beta)
  • Node.js version: 16

Code Snippet

import { test } from '@playwright/test'
import getport from 'get-port'

test.describe('suite', () => {
    test('test', async ({ page }) => {
        console.log(await getport())
        await page.goto('https://playwright.dev')
    })
})

Describe the bug

Playwright fails with no test found error due to import import getport from 'get-port' of a module.

PW_EXPERIMENTAL_TS_ESM=1 doesn't help anyhow in any combination with or without "type": "module" in the package.json

Error [ERR_REQUIRE_ESM]: require() of ES Module browser-tests/node_modules/get-port/index.js from browser-tests/test/test.spec.ts not supported.
Instead change the require of index.js in browser-tests/test/test.spec.ts to a dynamic import() which is available in all CommonJS modules.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions