-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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(remix): Rework dynamic imports of react-router-dom
.
#5897
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we use dynamicRequire
/loadModule
in place of require()
when we don't want bundlers to pick up loading of an optional dependency.
Does import('react-router-dom')
not run into the same issues as using require()
? Wont bundlers pick up this import, complain about the missing dependency and users will be forced to add react-router-dom
to their externals?
Yes, that's not like a replacement of That came up when I worked on #5796, where So, the alternative that worked was either a dynamic It actually worked fine without any external definitions when using dynamic relative paths: And, we went with Then, that broke monorepo projects where our relative paths can be wrong. (#5860) Not sure it would be much used if we made this a utility, though. But can be an ESM friendly fallback for |
Alternatively, we can traverse the directory tree up to some levels (2 - 3?), if the module is not found. That could allow us to avoid dealing with named imports and |
My understanding is that adding libraries to externals only fixes the issue for our bundling and users who are bundling themselves might need to do the same to avoid errors? Dynamic paths for import/require does give warnings with webpack but I guess webpack is not used for Remix which is a bonus! |
Sorry, I clicked the wrong button and closed the issue and now CI is running again. If remix/esbuild happily builds/bundles an app without |
Yes, exactly. Remix uses ESBuild, but still, like webpack, it throws errors when such thing happens. But, the case in Remix is that So, thinking now, this can only be applicable for opt-in integrations or specific SDKs as |
Sorry for coming late to this overall problem - maybe you covered this in previous discussions elsewhere besides #5810 and #5796 that I didn't see - but I'm not sure I understand why we need a dynamic require at all here. If we're worried about Maybe I'm missing something? |
If I remember correctly (not sure at all, it's been a while and this can be my internal conversation with myself 😅), the main reason we avoided using |
Yes this is correct - we couldn't vendor the types in. In addition, it was quite a bunch of code to vendor in, so we figured it wasn't worth it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there might be a better way around this, but in the spirit of just being able to unblock a user, I think we should 🚢 this and we can re-evaluate in the future.
Fixes: #5860
Ref: #5810 (comment)
Addedreact-router
as a peer dependency to flag it asexternal
, so Rollup won't complain insentry-javascript
's build time.Edit:
Defined
react-router
andreact-router-dom
asexternal
s in Rollup configuration, without making them peer dependencies.Added import by name as the first priority (which will work in monorepos) and relative imports as the second if the former fails. Logging error at the end if the latter fails too, without breaking the whole application.
This implementation is similar to the
loadModule
implementation below, only the priorities are swapped. (The other way works too)sentry-javascript/packages/utils/src/node.ts
Lines 46 to 63 in 69dfc35
Which makes me wonder if we could implement this as a utility, and start using it as a fallback wherever
dynamicRequire
may not work? (like Deno?)