algolia / instantsearch

⚑️ Libraries for building performant and instant search and recommend experiences with Algolia. Compatible with JavaScript, TypeScript, React and Vue.

Home Page:https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/js/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

react-hooks next example with npm package manager is not working

marcneander opened this issue Β· comments

commented

πŸ› 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

  1. clone your repo
  2. cd examples/react-hooks/next
  3. npm install
  4. 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

commented

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