Skip to content

[Bug]: [Regression]: Sync loader throws "context.conditions?.includes is not a function" on Node 22.15 #41311

Description

@likitakotian

Version

1.61.0

Steps to reproduce

Repro repo: https://github.com/likitakotian/Playwright-Testing
Branch: repro/playwright-161-conditions-bug
Folder: repro/

Failing CI (Node 22.15.0): https://github.com/likitakotian/Playwright-Testing/actions/runs/27570859984

Steps:

  1. git clone https://github.com/likitakotian/Playwright-Testing.git
  2. git checkout repro/playwright-161-conditions-bug
  3. cd repro
  4. Use Node 22.15.x (required — does NOT reproduce on Node 22.17+)
  5. npm ci
  6. npx playwright test

Or open the failing GitHub Actions run above.

Expected behavior

Tests load and run.

Actual behavior

Suite fails during module loading:

TypeError: context.conditions?.includes is not a function

Playwright 1.61 sync loader (esmLoaderSync in playwright/lib/common/index.js):

specifier = context.conditions?.includes("import") ? pathToFileURL(resolved).toString() : resolved;

Optional chaining means context.conditions exists but is not an Array.

Node 22.15–22.16 may pass context.conditions as a Set for require()-initiated
resolution in registerHooks: nodejs/node#59003
(fixed in Node 22.17: nodejs/node#59011)

Related: #41121 / #41138 (same line, Windows file:// case).

Suggested fix:
const isImport = context.conditions?.has?.('import') ?? context.conditions?.includes?.('import');

Additional context

No response

Environment

OS: Ubuntu latest (GitHub Actions)
Node: 22.15.0
@playwright/test: 1.61.0

Metadata

Metadata

Assignees

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions