-
-
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
Conditional require calls are hoisted incorrectly #6943
Comments
Hi @beckerei, thanks for the detailed writeup and research. Unfortunately, I am not sure if we can fix this fast and reliably, if at all. If you have suggestions I am all ears. Would doing a dynamic import work for you? From what I can see here the underlying call is using dynamic imports anyways so it should work if I am not mistaken. |
Yes, using a dynamic import in that case does solve the issue. However this is not a sustainable solution. Next supports conditional I think the only reliable solution is to keep the original import/export syntax and let the next build handle transformation. I'm afraid this will be hard to accomplish with rollup, if possible at all. |
@joshuajaco I have a feeling the whole ecosystem is moving away from CJS/require as a whole so I think we should let this simmer for a bit and see if more people run into this problem before rushing to a fix. Can I ask why you deem using dynamic imports a non-sustainable solution? |
In this case I agree, a dynamic import is actually the better solution. Beside the fact that you might need to import something synchronously, my biggest concern is actually that nextjs supports I think a warning message as mentioned in rollup/plugins#1177 (comment) would already help prevent this issue from remaining unnoticed. |
@lforst thank you for taking care :) |
@beckerei No worries. Let's hope this actually fixes your issue. I'll try not to forget to ping everybody once this is released. |
Hi, we just released an update that should fix this problem. https://github.com/getsentry/sentry-javascript/releases/tag/7.35.0 Let me know if upgrading the SDK fixes this issue for you! |
Works as expected now 👍 |
Is there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io)
Which package are you using?
@sentry/nextjs
SDK Version
7.33.0
Framework Version
Next 13.1.5
Link to Sentry event
No response
SDK Setup
Steps to Reproduce
Expected Result
The file should not be required
Actual Result
The file will be required regardless of the surrounding if-statement
Our understanding is that this behavior was introduced within the following PR
#6685
Enabeling
transformMixedEsModules
See also rollup/plugins#1177 which indicates that the rollup plugin can't fix this.
This is the recommended way to run MSW in your local env, see example https://github.com/vercel/next.js/blob/canary/examples/with-msw/pages/_app.tsx
The text was updated successfully, but these errors were encountered: