-
Notifications
You must be signed in to change notification settings - Fork 391
Could not import ReactDOMServer #3633
Comments
I feel like this is a new bug that was already attempted to be fixed in #3618, does that PR work for you? the situation is complicated as Webpack will try to import both the react 17 and react 18 import if it's a literal import, while pnpm removes the package if not in a literal import |
Thanks for confirming, we'll look more into it |
Sadly, it doesn't work for me. Although I don't get My environment:
Any upcoming fixes @Haroenv? |
Are you also using pnpm @whitebackdoor ? if so you can use the patch |
I'm using pnpm but patch doesn't fix the issue for me. |
Please open a new issue with reproduction in that case, I guess it might not be the same issue @whitebackdoor |
There are some cases where the combination of trying to make sure renderToString doesn't end up in a browser bundle, being runnable on esm + cjs, react 17 and 18, .js extension etc. blows up. One of those is pnpm caching removing "unused" packages. This PR introduces a new argument `renderToString` to `getServerState` so you can inject the dependency yourself, meaning the import is within your own code and won't be purged. ```js import { renderToString } from 'react-dom/server'; await getServerState(<App/>, renderToString); await getServerState(<App/>, import('react-dom/server').then(mod => mod.renderToString)); ``` fixes #3633 closes #3618 see vercel/next.js#40067
**Summary** There are some cases where the combination of trying to make sure renderToString doesn't end up in a browser bundle, being runnable on esm + cjs, react 17 and 18, .js extension etc. blows up. One of those is pnpm/vercel removing "unused" packages. <!-- Thanks for submitting a pull request! Please provide enough information so that others can review your pull request. --> <!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? Are there any linked issues? --> **Result** This PR introduces a new argument `renderToString` to `getServerState` so you can inject the dependency yourself, meaning the import is within your own code and won't be purged. ```js import { renderToString } from 'react-dom/server'; await getServerState(<App/>, renderToString); await getServerState(<App/>, import('react-dom/server').then(mod => mod.renderToString)); ``` <!-- Demonstrate the code is solid. Example: The exact commands you ran and their output, screenshots / videos if the pull request changes UI. --> fixes #3633 closes #3618 see vercel/next.js#40067 FX-1869 Co-authored-by: François Chalifour <francoischalifour@users.noreply.github.com>
…eact-instantsearch#3658) **Summary** There are some cases where the combination of trying to make sure renderToString doesn't end up in a browser bundle, being runnable on esm + cjs, react 17 and 18, .js extension etc. blows up. One of those is pnpm/vercel removing "unused" packages. <!-- Thanks for submitting a pull request! Please provide enough information so that others can review your pull request. --> <!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? Are there any linked issues? --> **Result** This PR introduces a new argument `renderToString` to `getServerState` so you can inject the dependency yourself, meaning the import is within your own code and won't be purged. ```js import { renderToString } from 'react-dom/server'; await getServerState(<App/>, renderToString); await getServerState(<App/>, import('react-dom/server').then(mod => mod.renderToString)); ``` <!-- Demonstrate the code is solid. Example: The exact commands you ran and their output, screenshots / videos if the pull request changes UI. --> fixes algolia/react-instantsearch#3633 closes algolia/react-instantsearch#3618 see vercel/next.jsalgolia/react-instantsearch#40067 FX-1869 Co-authored-by: François Chalifour <francoischalifour@users.noreply.github.com>
🐛 Bug description
I'm using react-instantsearch-hooks-server with Next.js (vercel/commerce) and I have this error only in production (Vercel), in local dev environment it works as expected.
The error started to appear with React 18, with 17 it worked.
🔍 Bug reproduction
I tried to reproduce the bug in a codesandbox but it doesn't happen.
I've setup a repo with an example at https://github.com/slackerzz/vercel-commerce
It is a clean vercel/commerce with a route
/algolia
where i use the ssr provider.The code is availabel at https://github.com/slackerzz/vercel-commerce/blob/main/site/pages/algolia.tsx
The index used is from https://codesandbox.io/s/github/algolia/react-instantsearch/tree/master/examples/hooks-next
In a local environment running
pnpm dev
the/algolia
route works as expected:After deploying the app to Vercel the same route returns a 500 error
Environment
Additional context
The text was updated successfully, but these errors were encountered: