-
Notifications
You must be signed in to change notification settings - Fork 796
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: use require for import in the middle #4546
fix: use require for import in the middle #4546
Conversation
Fixes an issue where bundlers (esbuild) fail to build because of es module interop issues
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #4546 +/- ##
==========================================
- Coverage 93.32% 92.83% -0.50%
==========================================
Files 84 328 +244
Lines 1694 9486 +7792
Branches 349 2035 +1686
==========================================
+ Hits 1581 8806 +7225
- Misses 113 680 +567 |
@dyladan can you change this from a draft PR to an actual PR? A change to this effect really needs to be merged. |
Yeah i'll update it |
It would be great to get this merged, as trigger.dev is currently blocked from bundling user code with esbuild into ESM, as we rely on |
+1, we also have reports of this breaking users, e.g. see getsentry/sentry-javascript#12009 - would be great to get this merged and released ❤️ |
I've been digging through lots of issues/PRs today that have been opened about this (#4717, #3954, #4519, #4691) but I'm still trying to grasp if this would actually solve the problem or if this would just get rid of the warning and cause us to run into different problems. All In reviewing I'm limited by my lack of familiarity with |
Not sure if this helps, but @timfish has combined some stuff together: Which seems to work for some people, at least (e.g. getsentry/sentry-javascript#12154 (comment)) |
I don't think any of the existing PRs will fix this. My best guess is that esbuild closely follows the spec whereas other bundlers paper over the mess. The obvious thing to do would be to fix the exports in |
We're having a hard time validating this fix because we don't have a reproducer. @mydea @ericallam do you have a repro we can use? I'm also not convinced that after we fix this error your problems will be solved. To my knowledge, bundlers work by removing import/require statements and inlining code. Our instrumentations rely on the functioning of those statements so it may turn out that once this problem is fixed the instrumentations may not work anyway.
This is 100% what I would prefer. We also talked about changing the web instrumentations to not use the same instrumentation base class as node instrumentations because they work differently (no require/import capture), which would also resolve this issue at least in web. |
`import-in-the-middle` has some ESM interop issues. From [here](open-telemetry/opentelemetry-js#4546 (comment)): > Specifically, namespace imports are required by the ESM spec to be objects. IITM's top-level export is not an object, but a callable function This causes [issues](open-telemetry/opentelemetry-js#4717) with some bundlers. Obviously bundled imports will not go through `import-in-the-middle` but using it should not inhibit bundlers as iitm can still hook build-in modules. This adds a `Hook` named export and changes one cjs and esm test to use that new export.
Closing this as I think this has been resolved by #4745. Feel free to re-open if that's incorrect 🙂 |
Fixes an issue where bundlers (esbuild) fail to build because of es module interop issues.
Import in the middle does not have a
default
export, which meansimport IITM from 'import-in-the-middle';
fails. Importing as a namespace withimport * as IITM from 'import-in-the-middle';
works, but causes issues with bundlers. Specifically, namespace imports are required by the ESM spec to be objects. IITM's top-level export is not an object, but a callable function (https://github.com/DataDog/import-in-the-middle/blob/c3c2c52c1915b47994af59d507c59029c1f1fae9/index.js#L91).This draft is to consider the possibility of using
require
instead ofimport
for this dependency.Related to #4519