Skip to content
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

Vite + react + useQuery = use-sync-external-store/shim problem #9670

Closed
willosof opened this issue May 4, 2022 · 3 comments · Fixed by #9675
Closed

Vite + react + useQuery = use-sync-external-store/shim problem #9670

willosof opened this issue May 4, 2022 · 3 comments · Fixed by #9675

Comments

@willosof
Copy link

willosof commented May 4, 2022

  • Vite 2.9.7
  • @apollo/client 3.6.2
  • React 18.1.0

More a compatibility issue, rather than a bug. And, to help others in need.

apollo/client uses useSyncExternalStore from use-sync-external-store/shim/index.js. This is not needed in React 18, since it has useSyncExternalStore built in. But vite likes ESM exported modules, so it will fail due to the old exporting in use-sync-external-store that @apollo/client requires when using useQuery.

My workaround for this is to add a resolve alias to the vite defineConfig

	resolve: {
		alias: {
			'use-sync-external-store/shim/index.js': 'react',

Works, but it's something I've spent countless hours trying to figure out :)

@willosof willosof changed the title vite.js + react 18 + useQuery = use-sync-external-store/shim problem. vite.js + react + useQuery = use-sync-external-store/shim problem May 4, 2022
@willosof willosof changed the title vite.js + react + useQuery = use-sync-external-store/shim problem Vite + react + useQuery = use-sync-external-store/shim problem May 4, 2022
@benjamn benjamn self-assigned this May 4, 2022
@benjamn
Copy link
Member

benjamn commented May 4, 2022

@willosof Please have a look at PR #9675, a fairly radical solution to this problem that I believe will work, because it's more ESM-friendly and avoids the use-sync-external-store/shim package entirely.

@benjamn
Copy link
Member

benjamn commented May 9, 2022

Related discussion: #9668 (comment)

@benjamn
Copy link
Member

benjamn commented May 9, 2022

@willosof Echoing #9668 (comment), if you update to version 3.7.0-alpha.3 by running

npm i @apollo/client@beta

you'll get a version of the library that includes PR #9675, which I believe makes this issue disappear!

Please let us know how that goes, and (with any luck) we can get these changes released in v3.6.4 (not really v3.7… that's just an easier way to test).

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.