fix(node): Use normal require call to import Undici#10388
Conversation
87bece1 to
1aaeb2e
Compare
| try { | ||
| // eslint-disable-next-line @typescript-eslint/no-var-requires | ||
| ds = dynamicRequire(module, 'diagnostics_channel') as DiagnosticsChannel; | ||
| ds = require('diagnostics_channel') as DiagnosticsChannel; |
There was a problem hiding this comment.
One reason this is there is because diagnostics_channel is only available for Node 16+, won't bundling break when bundling for older versions? (Like Node 14).
There was a problem hiding this comment.
I see it as follows: Every bundler has a built-in escape hatch because diagnostics_channel can always be manually externalized. The newer (sane) webpack versions automatically seem to externalize it out of the box, even on older Node.js versions.
Right now dynamicRequire seems to break fetch instrumentation on the Next.js canary: https://github.com/getsentry/sentry-javascript/actions/runs/7713179805/job/21023035517
With this change, it succeeds: https://github.com/getsentry/sentry-javascript/actions/runs/7712921252/job/21022104165
dynamicRequire effectively breaks bundled code. I see this more as a fix I think.
I have the soft opinion that this change is the lesser evil but I am not totally sure tbh. People affected would be people who are on old node versions && on old webpack versions. Wdyt?
|
I need to dwell on this for a bit. For some reason this doesn't even fix the issue I wanted to fix with this change: https://github.com/getsentry/sentry-javascript/actions/runs/7697605293/job/20975482956 🤔 |
size-limit report 📦
|
dd452b6 to
3847840
Compare
AbhiPrasad
left a comment
There was a problem hiding this comment.
I'm fine with making this change as long as we update troubleshooting docs accordingly.
|
I will merge this as soon as I have troubleshooting docs merged. Docs code freeze is in place right now tho. |
Dynamic require will work agains us in bundled server-side situations - e.g. Next.js. We are in Node.js world so
requireshould be available in any case. We also use it in the normalhttpandhttpsinstrumentation.