react-hooks next example with npm package manager is not working
marcneander opened this issue Β· comments
π Current behavior
After scratching my head with the error:
Error: Unable to retrieve InstantSearch's server state in
getServerState(). Did you mount the <InstantSearch> component?
I decided to try the next example in this repo and I get the same exact result using npm 8.19.2 and 9.6.2. Using yarn 1.22.17 works fine. Seems like you are relying on references between modules.
π Steps to reproduce
- clone your repo
- cd examples/react-hooks/next
- npm install
- npm run dev
Live reproduction
none
π Expected behavior
Should probably work
Package version
latest
Operating system
macOS
Browser
No response
Code of Conduct
- I agree to follow this project's Code of Conduct
This monorepo uses Yarn, so to be able to use the examples in this repo, you should use Yarn as well. If you copy the example only in a separate setup, like can be done through codesandbox, you can run it with npm too. https://codesandbox.io/s/github/algolia/instantsearch/tree/master/examples/react-hooks/next
This monorepo uses Yarn, so to be able to use the examples in this repo, you should use Yarn as well. If you copy the example only in a separate setup, like can be done through codesandbox, you can run it with npm too. https://codesandbox.io/s/github/algolia/instantsearch/tree/master/examples/react-hooks/next
sure, but moving the examples/react-hooks/next
example away from this repo and trying to install it with npm is still broken for me using nodejs LTS and the above stated npm versions.
I had colleagues try before i created this issue and they had the same problem.
Can also confirm, this does not work with NPM. but once I installed it with yarn it does work. that's odd behavior.
I can also confirm that installing the example with npm
yields the same error. It appears that the issue begins with the 6.39.0
release. It does not occur when you use 6.38.3
.
Very weird even though the dependency of React InstantSearch Hooks Web 6.42.2 depends on React InstantSearch Hooks 6.42.2, somehow npm installs version 6.38.3, which mismatches and thus throws that error. If you manually add the same version of React InstantSearch Hooks, 6.42.2, no such issue happens.
In the mean time of course, you can also continue to use Yarn, or create the app, separate from starting from this example.
This is because react-instantsearch-hooks-router-nextjs depends on 6.38.3, resulting in two copies of react-instantsearch-hooks
being installed. I'd argue that the yarn behavior is actually incorrect in this scenario.
βββ¬ react-instantsearch-hooks-router-nextjs@6.42.2
β βββ react-instantsearch-hooks@6.38.3
βββ¬ react-instantsearch-hooks-server@6.42.2
β βββ react-instantsearch-hooks@6.42.2
βββ¬ react-instantsearch-hooks-web@6.42.2
βββ react-instantsearch-hooks@6.42.2