You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since Next.js switched from using babel to using SWC we have encountered this issue. The library uses a configuration where it has a loader where until now it was recommended to use a dynamic import.
Now, this error is displayed:
Critical dependency: the request of a dependency is an expression
It can be "solved" by changing the dynamic import to require. The problem with require is that then, the bundle grows a lot compared to the dynamic import. With the dynamic import it creates different chunks and imports only the one that is needed.
Expected Behavior
It should work module.exports with dynamic imports.
Yes, for example for the configuration of libraries inside next.config.js! in order to get more context about the issue, you can read this tread in next-translate aralroca/next-translate#851 (comment)
This PR enables `ignoreDynamic` for common js modules which is detected
by `auto_cjs` pass.
Fixes#40231.
---
I verified that with this change the test reproduction does not fail
with import error.
---------
This closed issue has been automatically locked because it had no new activity for a month. 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
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
The issue was found in the Next-translate library:
aralroca/next-translate#851 (comment)
Since Next.js switched from using babel to using SWC we have encountered this issue. The library uses a configuration where it has a loader where until now it was recommended to use a dynamic import.
Now, this error is displayed:
It can be "solved" by changing the dynamic import to
require
. The problem withrequire
is that then, the bundle grows a lot compared to the dynamic import. With the dynamic import it creates different chunks and imports only the one that is needed.Expected Behavior
It should work
module.exports
with dynamic imports.Link to reproduction
https://github.com/aralroca/next-translate/tree/master/examples/complex
To Reproduce
To reproduce it using the link:
yarn && yarn start
To reproduce it in any project:
Create a file with a dynamic import and
module.export
:Then import and use this helper in some page loader (for example inside
getInitialProps
)The text was updated successfully, but these errors were encountered: