-
Notifications
You must be signed in to change notification settings - Fork 26.1k
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
Fails to dynamic import a module in a mono repo #37484
Comments
I believe this is not a Next.js issue, but rather how Node.js tries to resolve your imports here: You can do conditional loading, something like this should work: React.version.startsWith("18")
? import("react-dom/server")
: import("react-dom/server.js") |
Hello @balazsorban44 and thanks for your message! We tried to load the module using a condition based on the React version in this commit: algolia/react-instantsearch@195dbe8 We tried with all versions of "Next" in |
The issue is related to webpack/webpack#13865 and not Next.js, I'm closing this issue. Thanks for your help! |
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
$ npx --no-install next info Operating System: Platform: darwin Arch: x64 Version: Darwin Kernel Version 20.6.0: Tue Apr 19 21:04:45 PDT 2022; root:xnu-7195.141.29~1/RELEASE_X86_64 Binaries: Node: 16.10.0 npm: 7.24.0 Yarn: 1.18.0 pnpm: N/A Relevant packages: next: 12.1.6 react: 18.1.0 react-dom: 18.1.0
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
It fails to compile when trying to run a React InstantSearch Hooks with Next.js (and React 18) example in a mono repo: https://github.com/algolia/react-instantsearch/tree/feat/react-18-examples/examples/hooks-next
In React InstantSearch Hooks server module, we use two dynamic imports to import the correct
react-dom/server
dependency because the import varies depending on the installed React version (17 vs 18).Next.js fails to resolve the first import and
catch
doesn't get called.Expected Behavior
Running the example locally or in a CodeSandbox, everything is working fine: https://codesandbox.io/s/friendly-swartz-jfk4nj
Is Next.js failing to resolve the dynamic import because of the mono repo architecture?
To Reproduce
Steps to reproduce the issue in the mono repo:
git clone git@github.com:algolia/react-instantsearch.git
cd react-instantsearch && git checkout feat/react-18-examples
yarn
yarn build
yarn workspace hooks-next-example dev
orcd examples/hooks-next && yarn dev
Thank you!
The text was updated successfully, but these errors were encountered: