React Instantsearch Hooks Server: Module not found react-dom error is thrown when usign webpack #3512
Comments
Only from 6.25.0 onwards react 18 was supported for imports. I'll close this issue once the example on the documentation is updated to use a later version |
We originally raised this issue in the Next.js repo, but it seems to come from webpack: webpack/webpack#13865. It looks like their path resolution for dynamic imports that rely on |
While the webpack issue is not closed can this be solved by replacing the imports to use an expression? |
Unfortunately we can't do that, because the import path is different for v17 and v18, |
From what I understood in that webpack discussion I think we could still support both versions if we did something like this: const react18ServerModule = 'react-dom/server'
const preReact18ServerModule =
'react-dom/server.js'
// …
import(react18ServerModule).catch(() => {}),
import(preReact18ServerModule)y.catch(() => {}), However I wasn’t able to test this and right now I am on mobile, but just wanted to better explain my previous comment |
In next.js it seems that this is also solved in other way: https://github.com/vercel/next.js/blob/6108f10799b46bc0ef97373c913e23714e135942/packages/next/server/render.tsx#L92 (I think it looks cleaner if it works in this library) |
This is still WIP, but can be tried out via codesandbox now. fixes #3512
I haven't tried it yet, but made a draft PR converting the imports to expressions #3515 EDIT: have tried it out since, and seems to work as expected |
* fix(hooks-server): import react server via an expression This is still WIP, but can be tried out via codesandbox now. fixes #3512 * clarified comment
Thank you for the quick fix! |
The fix was released in v6.28.0. Let us know if the update is successful on your side 🙂 Thanks again! |
…ct-instantsearch#3515) * fix(hooks-server): import react server via an expression This is still WIP, but can be tried out via codesandbox now. fixes algolia/react-instantsearch#3512 * clarified comment
🐛 Bug description
When importing the
getServerState
function fromreact-instantsearch-hooks-server
the following error is thrown:🔍 Bug reproduction
Steps to reproduce the behavior:
hooks-ssr
example: https://github.com/algolia/react-instantsearch/tree/v6.22.0/examples/hooks-ssrLive reproduction:
https://codesandbox.io/s/delicate-https-ekihqc?file=/package.json
💭 Expected behavior
The application should load normally.
Environment
Additional context
I got this issue on a Next.js application. Next.js uses webpack and it seems that webpack performs some static analysis of imports at build time (ref). Since there are two dynamic imports on the
getServerState
function to try to import thereact-dom/server
module from different paths, webpack will throw an error at build time because thereact-dom/server.js
does not exist. It seems that this might be what is causing the problem.The text was updated successfully, but these errors were encountered: