Skip to content

fix: prefer registerHooks for ESM loader registration#40877

Open
danyalahmed1995 wants to merge 1 commit into
microsoft:mainfrom
danyalahmed1995:fix/node26-registerhooks-loader
Open

fix: prefer registerHooks for ESM loader registration#40877
danyalahmed1995 wants to merge 1 commit into
microsoft:mainfrom
danyalahmed1995:fix/node26-registerhooks-loader

Conversation

@danyalahmed1995
Copy link
Copy Markdown

Summary

Fixes #40868

This updates Playwright's ESM loader registration to use Node's newer module.registerHooks() API when it is available, while preserving the existing module.register() path as a fallback for older supported Node versions.

The issue reports the Node 26 module.register() deprecation warning. While the direct fix is to move newer Node versions toward registerHooks(), this PR also keeps the existing fallback path so the change does not break environments where registerHooks() is not available.

Changes

  • Prefer module.registerHooks() when supported by the current Node runtime.
  • Use synchronous resolveSync / loadSync hooks for the registerHooks() path.
  • Preserve the existing module.register() behavior as the fallback path.
  • Share the common resolver preparation logic between async and sync loader hooks.
  • Add regression coverage for both registration branches:
    • registerHooks() is preferred when available.
    • module.register() is still used when registerHooks() is unavailable.

Notes

module.registerHooks() expects synchronous hooks, so this PR does not pass the existing async hooks directly into the new API. Instead, it adds sync hook variants for the newer registration path while keeping the async loader behavior for the existing module.register() flow.

The fallback is intentionally kept because the reported Node 26 warning only covers the newer runtime behavior, but Playwright still needs to preserve compatibility with older supported Node versions.

Validation

  • npm run build
  • npm run tsc
  • npm run ttest -- tests/playwright-test/loader.spec.ts --grep "playwright ESM loader registration"
  • npm run ttest -- tests/playwright-test/esm.spec.ts --grep "should import esm from ts when package.json has type module"
  • git diff --check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: module.register() deprecation warning (DEP0205) on Node 26

1 participant