Skip to content

fix(esm): register synchronous hooks when require(esm) is disabled - #11277

Closed
joeyzhao2018 wants to merge 1 commit into
masterfrom
joey/fix-lambda-sync-loader
Closed

joeyzhao2018 wants to merge 1 commit into
masterfrom
joey/fix-lambda-sync-loader

Conversation

@joeyzhao2018

Copy link
Copy Markdown
Contributor

What does this PR do?

AWS Lambda can disable require(ESM), which prevents dd-trace/register.js from loading the synchronous hook helpers and makes Node.js 26 emit DEP0205 when the tracer falls back to module.register().

Share a CommonJS loader implementation between the CommonJS preloader and the ESM loader entry point. Build the pure import-in-the-middle helper as CommonJS through the existing vendor pipeline, using the currently pinned dependency and preserving its public instrumentation registry. Keep matcher initialization lazy and retain the asynchronous fallback on older runtimes.

Motivation

Allow Lambda applications to install synchronous module hooks without enabling experimental module loading or suppressing deprecation warnings.

Additional Notes

Validation:

  • 42 focused registration, loader, module-event, and source-rewriting checks pass on Node 26.12.0. The regression matrix covers CommonJS and ESM applications through both initialization entry points with require(ESM) disabled.
  • Packaged initialization suite: 95 passing, 6 skipped.
  • Patched v5 source snapshot: 36 passing.
  • Real shim bootstrap in local Lambda images: Node 24.21.0 and 26.1.0 use synchronous hooks with experimental module loading disabled and no warnings; v5 on Node 18.20.8 retains the asynchronous fallback.
  • npm run lint, npm run lint:editorconfig, and git diff --check pass.

Deployed AWS validation, release-line backport artifacts, and a published Lambda layer remain outstanding.

@joeyzhao2018
joeyzhao2018 requested review from a team as code owners November 17, 2026 01:46
@joeyzhao2018
joeyzhao2018 requested review from rochdev and tlhunter and removed request for a team November 17, 2026 01:46
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-17T01:49:16.240494Z 54b6f73 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Pipelines  Tests

✨ Unblock PR with BitsAI

❌ Errors

Your PR has failed checks. Please review the issues below and take necessary action before merging.

🚦 38 Pipeline jobs failed

Test Optimization | integration-vitest (node-oldest, vitest.core, vitest-all) — ❌ 2 tests failed

View more details · View in GitHub Actions

❌ vitest@3.2.6 propagates test span context to HTTP requests and hooks during test execution from integration-tests/vitest/vitest.core.spec.js
should have http span with matching trace_id

↳ ❄️ Known flaky: vitest@1.6.0 propagates test span context to HTTP requests and hooks during test execution from integration-tests/vitest/vitest.core.spec.js

APM Capabilities | tracing-ubuntu (oldest) — 🔧 Needs a code fix, caused by this PR

View more details · View in GitHub Actions

APM Integrations | crypto — 🔧 Needs a code fix, caused by this PR

View more details · View in GitHub Actions

View all 38 failed jobs.

⚠️ Warnings

🧪 42 Tests failed in 1 job

Test Optimization | integration-vitest-browser — ❌ 42 tests failed

View more details · View in GitHub Actions

❌ vitest@5.1.0 Browser Mode applies Auto Test Retries to browser tests from integration-tests/vitest/vitest.browser.spec.js   View in Datadog
est.config.mjs (120:41) [UNRESOLVED_IMPORT] Could not resolve '@vitest/browser-webdriverio' in vitest.config.mjs
     ╭─[ vitest.config.mjs:120:42 ]
     │
 120 │     const { webdriverio } = await import('@vitest/browser-webdriverio')
     │                                          ──────────────┬──────────────  
     │                                                        ╰──────────────── Module not found, treating it as an external dependency
─────╯

vitest.config.mjs (246:47) [UNRESOLVED_IMPORT] Could not resolve '@cloudflare/vitest-pool-workers/config' in vitest.config.mjs
     ╭─[ vitest.config.mjs:246:48 ]
...
❌ vitest@5.1.0 Browser Mode applies Early Flake Detection repetitions to new browser tests from integration-tests/vitest/vitest.browser.spec.js   View in Datadog
est.config.mjs (120:41) [UNRESOLVED_IMPORT] Could not resolve '@vitest/browser-webdriverio' in vitest.config.mjs
     ╭─[ vitest.config.mjs:120:42 ]
     │
 120 │     const { webdriverio } = await import('@vitest/browser-webdriverio')
     │                                          ──────────────┬──────────────  
     │                                                        ╰──────────────── Module not found, treating it as an external dependency
─────╯

vitest.config.mjs (246:47) [UNRESOLVED_IMPORT] Could not resolve '@cloudflare/vitest-pool-workers/config' in vitest.config.mjs
     ╭─[ vitest.config.mjs:246:48 ]
...
↳ and 40 more — View all

ℹ️ Info

No other issues found (see more)

❄️ No new flaky tests detected

🔄 Datadog retried 45 tests - 1 passed on retry View in Datadog

🎯 Code Coverage (details)
• Patch Coverage: 96.15%
• Overall Coverage: 71.96% (-26.57%)

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 54b6f73 | Docs | View more details | Give us feedback!

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 54b6f737a4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread vendor/rspack.config.js
// Only the pure loader helper is bundled. The public import-in-the-middle registry
// and its generated wrappers must keep using the application's shared dependency.
// A CommonJS build lets synchronous preloads install hooks when require(esm) is disabled.
module.exports = [config, {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Update the license tests for the multi-compiler configuration

Changing this export from an object to an array breaks the existing consumer in scripts/test/vendor-licenses.spec.js: its bundle() helper still reads config.plugins[0], which now throws TypeError: Cannot read properties of undefined (reading '0'). Consequently, the license tests run by npm run test:scripts in .github/workflows/project.yml fail before checking any bundled licenses. Update that helper to select the dependencies configuration and preserve its output and plugin settings.

Useful? React with 👍 / 👎.

@codecov

codecov Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.15385% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.06%. Comparing base (f159c6a) to head (54b6f73).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
register.js 50.00% 2 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (f159c6a) and HEAD (54b6f73). Click for more details.

HEAD has 7 uploads less than BASE
Flag BASE (f159c6a) HEAD (54b6f73)
platform 1 0
llmobs 1 0
instrumentation 1 0
appsec 1 0
apm-capabilities 1 0
apm-integrations 1 0
test-optimization 1 0
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #11277       +/-   ##
===========================================
- Coverage   99.13%   72.06%   -27.07%     
===========================================
  Files        1118      610      -508     
  Lines      184942    95439    -89503     
  Branches       82        9       -73     
===========================================
- Hits       183338    68779   -114559     
- Misses       1603    26660    +25057     
+ Partials        1        0        -1     
Flag Coverage Δ
ai-guard 63.27% <ø> (-0.02%) ⬇️
apm-capabilities ?
apm-integrations ?
appsec ?
debugger 70.95% <82.69%> (-0.13%) ⬇️
instrumentation ?
llmobs ?
master-coverage 72.06% <94.23%> (?)
openfeature 68.14% <ø> (-0.02%) ⬇️
platform ?
profiling 66.09% <ø> (-0.02%) ⬇️
serverless 65.50% <94.23%> (-0.14%) ⬇️
test-optimization ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pabloerhard pabloerhard left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m unsure whether this is the approach we should take. Can we hold off until we reach an agreement?

@rochdev

rochdev commented Nov 19, 2026

Copy link
Copy Markdown
Member

If this is on hold, could it be converted to draft to stop notifications?

@joeyzhao2018

Copy link
Copy Markdown
Contributor Author

#11296

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants