hydrogen: React version mismatch when creating new projects

EDIT: See current workaround in https://github.com/Shopify/hydrogen/issues/2040#issuecomment-2084636795

What is the location of your example repository?

New

Which package or tool is having this issue?

Hydrogen

What version of that package or tool are you using?

2024.4.1

What version of Remix are you using?

2.9.1

Steps to Reproduce

Background:

macOS Sonoma 14.2.1 (23C71) Node v20.12.2

Steps to reproduce

  • Run npm create @shopify/hydrogen@latest
  • Enter y to install

Expected Behavior

Create a Hydrogen app

Actual Behavior

Warning: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.
Warning: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.

  ERROR  Cannot read properties of null (reading 'useState')

 /Users/richard.homewood/.npm/_npx/e1eac94ad41cc36f/node_modules/@shopify/cli-kit/node_modules/react/cjs/react.development.js:1622:21

 1619: }
 1620: function useState(initialState) {
 1621:   var dispatcher = resolveDispatcher();
 1622:   return dispatcher.useState(initialState);
 1623: }
 1624: function useReducer(reducer, initialArg, init) {
 1625:   var dispatcher = resolveDispatcher();

About this issue

  • Original URL
  • State: closed
  • Created 2 months ago
  • Reactions: 16
  • Comments: 34 (14 by maintainers)

Most upvoted comments

You are not doing something wrong, we need to wait until Monday to get it fixed.

The fix is now released and npm create @shopify/hydrogen@latest can be use to create new project.

๐Ÿ—’๏ธ that you will see Warning: Could not find ts-node while running the project locally. This is to a known issue and can be safety ignore.

cc HeisUser

HI folks, just ensuring that this issue have the attention of the team and we are working on re-producing and coming up with solution. Thank you all for your patience.

After some research, it looks like this is something that needs to be fixed properly in @shopify/cli-kit.

For the time being, weโ€™ve added a better error when this happens: image

The current workaround is to run npm create @shopify/hydrogen@latest --legacy-peer-deps to avoid the React mismatch during project creation. However, you might have already a wrong version installed in cache so, if that still doesnโ€™t work, try npm cache clean --force first. Or simply copy paste the new command shown in the warning (it should give you a random cache directory to bypass cache).

I donโ€™t know where this is heading ๐Ÿ˜•. Has anyone taken any action to resolve this issue? I need to sort this out, so any progress update would be much appreciated. Thanks, everyone ๐Ÿ˜€.

An upstream dependency mismatch is found in @shopify/cli-kit and had been reported to appropriate team.

Looks like this issue might have something to do with having multiple versions of react. Looks to me that hydrogen-react is using 18.0.0 while all the other packages involved with hydrogen are using 18.2.0. I managed to force hydrogen-react to use react and react-dom 18.2.0 and it seems to all be working as intended. Had to fork the repo and install it that way but it looks to now be working.

Working great, thanks all!

npm create @shopify/hydrogen@latest
Need to install the following packages:
@shopify/create-hydrogen@4.3.8
Ok to proceed? (y) y
?  Connect to Shopify:
โœ”  Use sample data from mock.shop (You can connect a Shopify account later)

?  Where would you like to create your storefront?
โœ”  test-install

?  Select a language:
โœ”  JavaScript

?  Install dependencies with npm?
โœ”  Yes

?  Create a global `h2` alias to run commands instead of `npx shopify hydrogen` ?
โœ”  Yes

โ•ญโ”€ info โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚                                                                                                                                          โ”‚
โ”‚  You'll need to restart your terminal session to make `h2` alias available.                                                              โ”‚
โ”‚                                                                                                                                          โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

โ•ญโ”€ success โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚                                                                                                                                          โ”‚
โ”‚  test-install is ready to build.                                                                                                         โ”‚
โ”‚                                                                                                                                          โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

?  Do you want to scaffold routes and core functionality?
โœ”  Yes, set up now

?  Select a URL structure to support multiple markets:
โœ”  Subfolders (example.com/fr-ca/...)


โ•ญโ”€ success โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚                                                                                                                                                     โ”‚
โ”‚  Storefront setup complete!                                                                                                                         โ”‚
โ”‚                                                                                                                                                     โ”‚
โ”‚    Shopify:   Mock.shop                                                                                                                             โ”‚
โ”‚    Language:  JavaScript                                                                                                                            โ”‚
โ”‚    Markets:   Subfolders                                                                                                                            โ”‚
โ”‚    Routes:                                                                                                                                          โ”‚
โ”‚      โ€ข Home (/ & /:catchAll)                                                                                                                        โ”‚
โ”‚      โ€ข Page (/pages/:handle)                                                                                                                        โ”‚
โ”‚      โ€ข Cart (/cart/* & /discount/*)                                                                                                                 โ”‚
โ”‚      โ€ข Products (/products/:handle)                                                                                                                 โ”‚
โ”‚      โ€ข Collections (/collections/*)                                                                                                                 โ”‚
โ”‚      โ€ข Policies (/policies & /policies/:handle)                                                                                                     โ”‚
โ”‚      โ€ข Blogs (/blogs/*)                                                                                                                             โ”‚
โ”‚      โ€ข Account (/account/*)                                                                                                                         โ”‚
โ”‚      โ€ข Search (/api/predictive-search & /search)                                                                                                    โ”‚
โ”‚      โ€ข Robots (/robots.txt)                                                                                                                         โ”‚
โ”‚      โ€ข Sitemap (/sitemap.xml)                                                                                                                       โ”‚
โ”‚                                                                                                                                                     โ”‚
โ”‚  Next steps                                                                                                                                         โ”‚
โ”‚                                                                                                                                                     โ”‚
โ”‚    โ€ข Run `cd test-install && npm run dev`                                                                                                           โ”‚
โ”‚                                                                                                                                                     โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

EDIT: See current workaround in #2040 (comment)

What is the location of your example repository?

New

Which package or tool is having this issue?

Hydrogen

What version of that package or tool are you using?

2024.4.1

What version of Remix are you using?

2.9.1

Steps to Reproduce

Background:

macOS Sonoma 14.2.1 (23C71) Node v20.12.2

Steps to reproduce

  • Run npm create @shopify/hydrogen@latest
  • Enter y to install

Expected Behavior

Create a Hydrogen app

Actual Behavior

Warning: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.
Warning: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.

  ERROR  Cannot read properties of null (reading 'useState')

 /Users/richard.homewood/.npm/_npx/e1eac94ad41cc36f/node_modules/@shopify/cli-kit/node_modules/react/cjs/react.development.js:1622:21

 1619: }
 1620: function useState(initialState) {
 1621:   var dispatcher = resolveDispatcher();
 1622:   return dispatcher.useState(initialState);
 1623: }
 1624: function useReducer(reducer, initialArg, init) {
 1625:   var dispatcher = resolveDispatcher();

This issue still happening while updated to the latest version of dependencies with the commands as follows : $ npm install -g npm-check-updates --verboseโ€จ $ ncu $ ncu -u --verbose $ npm install --legacy-peer-deps $ npm update --save $ npm run dev

But this issue has solved and no problems without update latest version of dependencies and just run the command as follow : $ npm create @shopify/hydrogen@latest --legacy-peer-deps $ npm run dev

Anyways, this issue of React version mismatched still happening with Iโ€™d updated with commands as follows : $ npm install react@latest react-dom@latest $ npm run dev

Version Details as follow : Current Shopify CLI version: 3.59.2 Node v22.0.0 npm 10.6.0 MacOS 14.4.1 (23E224) @Intel-besed

Here is the errors on my system as follow: $ npm run dev `hydro-storefront@1.0.9 dev shopify hydrogen dev --codegen

Port 3000 is in use, trying another oneโ€ฆ

Environment variables injected into MiniOxygen:

SESSION_SECRET from local .env PUBLIC_STORE_DOMAIN from local .env

โžœ Local: http://localhost:3001/ โžœ Network: use --host to expose โžœ press h + enter to show help

Warning: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:

  1. You might have mismatching versions of React and the renderer (such as React DOM)

  2. You might be breaking the Rules of Hooks

  3. You might have more than one copy of React in the same app See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem. The above error occurred in the <BoxWithBorder> component:

    at BoxWithBorder (file:///usr/local/var/www/gitHub/hydro-storefront/node_modules/@shopify/cli-kit/dist/private/node/ui/components/Banner.js:23:26) at Banner (file:///usr/local/var/www/gitHub/hydro-storefront/node_modules/@shopify/cli-kit/dist/private/node/ui/components/Banner.js:61:19) at Alert (file:///usr/local/var/www/gitHub/hydro-storefront/node_modules/@shopify/cli-kit/dist/private/node/ui/components/Alert.js:7:18) at App (file:///usr/local/var/www/gitHub/hydro-storefront/node_modules/ink/build/components/App.js:19:9)

React will try to recreate this component tree from scratch using the error boundary you provided, InternalApp.

ERROR Cannot read properties of null (reading โ€˜useStateโ€™)

node_modules/@shopify/cli-kit/node_modules/react/cjs/react.development.js:1622:21

1619: } 1620: function useState(initialState) { 1621: var dispatcher = resolveDispatcher(); 1622: return dispatcher.useState(initialState); 1623: } 1624: function useReducer(reducer, initialArg, init) { 1625: var dispatcher = resolveDispatcher();

  • useState (node_modules/@shopify/cli-kit/node_modules/react/cjs/react.development.js:1622:21)
  • useLayout (node_modules/@shopify/cli-kit/dist/private/node/ui/hooks/use-layout.js:7:33)
  • BoxWithBorder (node_modules/@shopify/cli-kit/dist/private/node/ui/components/Banner.js:24:27)
  • renderWithHooks (node_modules/react-reconciler/cjs/react-reconciler.development.js:6659:18)
  • mountIndeterminateComponent (node_modules/react-reconciler/cjs/react-reconciler.development.js:11276:13)
  • beginWork (node_modules/react-reconciler/cjs/react-reconciler.development.js:12799:16)
  • beginWork$1 (node_modules/react-reconciler/cjs/react-reconciler.development.js:19608:14)
  • performUnitOfWork (node_modules/react-reconciler/cjs/react-reconciler.development.js:18742:12)
  • workLoopSync (node_modules/react-reconciler/cjs/react-reconciler.development.js:18648:5)
  • renderRootSync (node_modules/react-reconciler/cjs/react-reconciler.development.js:18616:7)

โ€บ Warning: Could not find ts-node at /usr/local/var/www/gitHub/hydro-storefront/node_modules/@shopify/cli/dist/index-e6f8190d.js. Please โ€บ ensure that ts-node is a devDependency. Falling back to compiled source.`

Anyone getting this warning after starting dev?

Screenshot 2024-04-29 170702

I tried running h2 codegen --watch but I get this error even though i have the latest version of @shopify/hydrogen installed:

Screenshot 2024-04-29 170925

Codegen is just not working for some reason.