Skip to content

Error: require() of ES Module in Playwright #1

Closed
@kettanaito

Description

@kettanaito

Reproduction steps

  1. Create a Playwright test.
import { createTestHttpServer } from '@epic-web/test-server/http'
import { test, expect } from '../playwright.extend'

test('', () => {
  createTestHttpServer()
})
  1. Run the text via npx playwright test.
  2. See the following error:
Error: require() of ES Module /node_modules/.pnpm/@[email protected]/node_modules/@epic-web/test-server/lib/http.js from /test/browser/sse-api/sse.server.connect.test.ts not supported.
Instead change the require of http.js in /test/browser/sse-api/sse.server.connect.test.ts to a dynamic import() which is available in all CommonJS modules.

Expected behavior

There must be no error, the test should compile and run.

Context

The error is a bit odd because the package is ESM, and there's no require() statements. I suspect what's happening is Playwright transpiles the ESM test to CJS, and because the imported package is ESM-only, it fails?

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