-
Notifications
You must be signed in to change notification settings - Fork 27k
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
Dependencies with import
condition imported as promises
#49898
Comments
friendly 🏓 @huozhi |
Tried with latest canary the issue is still preserved, will investigate on that 🙏 |
Is there any case that you have to remain a "commonjs.js" to re-export the esm bundle? For app directory it bundles everything, and we disabled the esm resolving to prefer cjs. If you're using esm import/export synatx it will handle properly. |
It was likely just an old setup that resulted in this but I imagine people could try to write code like this to get direct access to I feel like this issue is more of a "shouldn't this work?" rather than "we can't live without it".
I don't quite follow this. Some examples of this behavior would be appreciated. |
It seems any dual package that would have this problem. For app router: It bundles everything, so external dependencies can be extracted, then the external esmodule could be handled as properly. For pages + app router: |
With change from #56532 we keep the original external resolving logic, so it gonna be aligned between nextjs pages app (with app directort) and nextjs pages app (without app directory). But the result will still remain as promise due to the reason explained above. |
@Andarist @michaldudak the alignment is landed in v13.5.5-canary.9, I'd like to close this for now. Since pages dir is not bundled so we cannot handle the |
Thanks for taking a look at this! The fix doesn't solve our problem in MUI docs, but we were able to work around it by setting |
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
Which area(s) of Next.js are affected? (leave empty if unsure)
No response
Link to the code that reproduces this issue
https://github.com/emmatown/test-next-esm
To Reproduce
Run
next build
in pages-dir, app-dir, and pages-dir-with-app-dir and compare the logs. We're logging the result ofimport * as x from "../commonjs";
in each case:Using the pages directory
Note that the imported value is a promise, which is unexpected.
Using the app directory
This is the correct behavior.
Using the pages directory with the app directory present
This is also correct.
Describe the Bug
The issue appeared in the MUI Core repository when we updated Emotion to the latest version (11.11.0). This version of Emotion includes an addition of the
import
condition in its package.json (see https://github.com/emotion-js/emotion/pull/3029/files#diff-1f344ac391eeecc21ec0f01fb07430a47f4b80d20485c125447d54c33c4bbfc4R16).It causes the next build output (a built page inside .next/server/pages) to change from
to
which, in turn causes dependent
import
s to be dynamic (= return a promise instead of the actual value), breaking our app.We have also noticed a similar bug when installing the Floating UI package (which also has the
import
condition in its package.json (mui/material-ui#35914))Emotion issue for reference: emotion-js/emotion#3032 (comment)
Expected Behavior
Import dependencies without wrapping them in promises when the
import
condition is used.Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
NEXT-1565
The text was updated successfully, but these errors were encountered: