fix(guardrails): load package.json at module level for proxyquire compat on Node 26#9096
fix(guardrails): load package.json at module level for proxyquire compat on Node 26#9096rochdev wants to merge 1 commit into
Conversation
Node.js v26 changed how require() inside function bodies is wired —
it no longer goes through module.require dynamically, so proxyquire's
stub interception (which patches module.require via require.extensions)
had no effect for the require('../../../../package.json') call inside
guard(). Moving it to module level ensures the stub is applied during
the load-time window when proxyquire's patch is active, making the
unit-guardrails test pass on all supported Node.js versions.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Overall package sizeSelf size: 6.37 MB Dependency sizes| name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.2.0 | 104.26 kB | 843.44 kB | | opentracing | 0.14.7 | 194.81 kB | 194.81 kB | | dc-polyfill | 0.1.11 | 25.74 kB | 25.74 kB |🤖 This report was automatically generated by heaviest-objects-in-the-universe |
🎉 All green!🧪 All tests passed 🔗 Commit SHA: 9f2f81f | Docs | Datadog PR Page | Give us feedback! |
BenchmarksBenchmark execution time: 2026-06-26 18:42:40 Comparing candidate commit 9f2f81f in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 2251 metrics, 35 unstable metrics.
|
|
Closing in favor of a different resolution. After deeper investigation, the root cause is not a Node 26 proxyquire bug. The That integration test passed on Node 26 on the same v5.x run where the unit test failed ( Replacing this with a PR that removes the redundant unit test.
|
Summary
require('../../../../package.json')from inside theguard()function body to module level inpackages/dd-trace/src/guardrails/index.jsunit-guardrailsCI failure introduced in v5.110.0 proposal #9095 on Node.js v26Root Cause
Node.js v26 changed how
require()inside function bodies is wired — it no longer callsmodule.requiredynamically. Proxyquire stubs modules by patchingmodule.requirevia therequire.extensions['.js']handler at load time. Since therequire('../../../../package.json')call was insideguard()(called after load), proxyquire's patch had no effect on Node 26. The realpackage.json(nodeMaxMajor: 27) was used instead of the test stub, soNODE_MAJOR (26) >= 27evaluated tofalse, the guard didn't abort, and the test failed.Moving the require to module level ensures it runs during the window when proxyquire's patch is active, fixing the test on all Node versions. It's also a minor perf improvement (reads
package.jsononce instead of on everyguard()call).Test plan
mocha packages/dd-trace/test/guardrails/index.spec.js— 1 passingeslint packages/dd-trace/src/guardrails/index.js— 0 errors