gatsby: Ambiguous "StoreStateProvider" error for all gatsby commands
Description
After updating Gatsby from 2.17.7 to 2.18.4, running any kind of gatsby command causes an error. There is literally no context though.
> gatsby clean
The above error occurred in the <StoreStateProvider> component:
in StoreStateProvider
in App
React will try to recreate this component tree from scratch using the error boundary you provided, App.
Warning: App: Error boundaries should implement getDerivedStateFromError(). In that method, return a state update to display an error message or fallback UI.
> gatsby build
The above error occurred in the <StoreStateProvider> component:
...
Environment
Unfortunately, I can’t run gatsby info --clipboard
, since it crashes with the same StateStoreProvider
error as the other commands. I reverted my Gatsby version again and ran this command. Note that the Gatsby version in the output below is incorrect.
System:
OS: Windows 10
CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
Binaries:
npm: 6.9.0 - C:\Program Files\nodejs\npm.CMD
Languages:
Python: 2.7.16 - C:\Python27\python.EXE
Browsers:
Edge: 44.18362.267.0
npmPackages:
gatsby: ^2.17.7 => 2.17.7
gatsby-source-apiserver: ^2.1.4 => 2.1.4
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 36
- Comments: 61 (14 by maintainers)
Links to this issue
Commits related to this issue
- npm audit fix and fix gatsby/react dependency https://github.com/gatsbyjs/gatsby/issues/19827#issuecomment-559898690 — committed to knpwrs/knpw.rs by knpwrs 4 years ago
- :arrow_up: Update react, react-dom, and gatsby Having this issue: https://github.com/gatsbyjs/gatsby/issues/19827 Solution: https://github.com/gatsbyjs/gatsby/issues/19827#issuecomment-559898690 htt... — committed to paxcodes/portfolio by deleted user 4 years ago
- Fix Gatsby build Per this issue, gatsby-cli needs to be installed globally! https://github.com/gatsbyjs/gatsby/issues/19827 — committed to cloudflare/workers.cloudflare.com by kristianfreeman 4 years ago
- Update node packages per this link https://github.com/gatsbyjs/gatsby/issues/19827#issuecomment-559275701 — committed to BenjaminCatarevas/bencatarevas.com by deleted user 4 years ago
- Re-install gatsby and react due to version conflicts https://github.com/gatsbyjs/gatsby/issues/19827#issuecomment-559898690 — committed to jobcast/jobcast-www by johnnyoshika 4 years ago
- Bump React, Gatsby, and regenerate yarn.lock When attempting to run the website in development, after making no changes, I was greeted with the following error message: > The above error occurred in... — committed to sean0x42/seanbailey.dev by sean0x42 4 years ago
I fixed the problem! I used npm to uninstall, then (re)install
react
,react-dom
, andgatsby
. I did it in that exact order (I don’t believe ordering would matter, but FYI in case it does).npm ls react
shows two versions, but they’re the same and marked as “deduped”:I had a similar problem earlier today, what worked for me was to update react, react-dom and gatsby, erase node_modules and package-lock.json. Finally I run npm install again and everything worked fine
Yesterday I’ve spent half day just to find out that In my case gatsby build/develop is working fine when deps are installed with yarn.
I ran into this issue today when running
gatsby develop
on an older project (last time running gatsby develop was in the Fall)I fixed by doing a combination of the above (very helpful!) suggestions.
Can confirm this worked:
gatsby clean
- started with this to see if it resolvednode_modules
npm install
It wasn’t resolved at this point so I followed the advice to do this:
npm uninstall react react-dom gatsby
npm install react react-dom gatsby
This worked perfectly.
Even though this doesn’t have much activity, I don’t think it’s stale
To desperate devs looking for problems that should not exist in the first place just:
-remove node_modules folder -delete package.lock.json -run npm i
I’ve successfully resolve the issue by upgrading react and react-dom to 16.12.0 and then upgrade gatsby to 2.18.7.
Important: Make sure you run “gatsby clean” after upgrading react, react-dom and gatsby.
Ditto to the above, this solution fixed things for me as well.
I’ve had an issue seemingly linked to this problem #26998
Solved using a custom webpack config to resolve
react
:Everything runs smoothly now.
Personally I have to delete
node_modules
folder andpackage-lock.json
Then, I upgradereact
,react-dom
andgatsby
:Don’t forget to update
gatsby-cli
to the latest version and run agatsby clean
After that,gatsby develop
works like a charm!Removed node_modules folder & package-lock.json file. Ran npm install and all good again.
Also having this same issue. Updated react and gatsby but still having the same issues. Also tried to clean after update, issue persists.
“gatsby”: “^2.18.11” “react”: “^16.12.0” “react-dom”: “^16.12.0”
Even though I am a developer noob, I’ve got to share how I fixed this incase it helps anyone else:
I was trying to spin up Gatsby/Sanity blog from https://www.sanity.io/create?template=sanity-io/sanity-template-gatsby-blog StoreStateProvider error was harassing me.
I went into the /web directory and checked the React versions using
npm ls react
, there was two different versions in gatsby and gatsby-cli.FIX: npm install gatsby-cli in the web directory. Then
npm ls react
showed only one version of React, react@17.0.1I found that the issue happens only when the default gatsby logger is used. The particular logger that will be used is controlled via GATSBY_LOGGER process env. The issue is not reproducible if the default logger is changed for example with json logger.
Seems like it has to do with a compatibility issue between React and Gatsby. If you’re installing dependencies from scratch (without a lock file) your package manager (either yarn or npm) will just get the latest (allowed by restraints in package.json) version.
In my case, the react version was locked down in my
package-lock.json
, therefore it was not updated alongside Gatsby even on a fresh install.Still running into this issue.
Steps to reproduce:
gatsby new
to create new projectnpm i --save node-sass gatsby-plugin-sass
gatsby develop
Result
This was fixed by implementing the instructions by doing the following as described above ☝️
So what I did (after reading everything so far) was I changed the version in the package.json file of Gatsby 2.18.7 and ran
npm i
It workedI tried a lot of these comments, but as someone who hasn’t used
npm
for any part of the process I thought I would write up what specifically worked for me.My Setup:
Win10, Yarn installed via .msi, Gatsby via
yarn global
. Usingyarn
for all Gatsby projects.Problem:
Any
gatsby {command}
would yield theStoreStateProvider
error, butnpx gatsby {command}
worked.Solution:
.cache
and/node_modules
if they exist.react
andreact-dom
are updated,"^16.13.0"
as of this writing.yarn global remove gatsby gatsby-cli
to remove the broken CLI.yarn global add gatsby gatsby-cli
to reinstall the CLI.gatsby -v
or anothergatsby {command}
and it should work.Output:
After getting hands on reproduction case for it:
This seems to come from case with npm installs that user defined version of
react
installs innode_modules
, whilegatsby-cli
version of react will install innode_modules/gatsby/node_modules
.Because
ink
seems to get installed innode_modules
itsreact
imports will use different imports thangatsby-cli
ones which leads to case:And https://reactjs.org/warnings/invalid-hook-call-warning.html#duplicate-react explains this pretty well, but only suggestion there (to use
yarn resolutions
won’t work because this is issue with hownpm
seems to decidenode_modules
structure and not yarn)Only solution (very hacky at that) that comes to my mind right now is to override Node.js module resolution and hardcode
react
to one defined bygatsby-cli
. It might be ok to do so (that’s how PnP is implemented at least in yarn v1)deleted package-lock.json deleted node_modules ran npm i
worked for me 😄
Upgrading gatsby to 2.18.7 as suggested by @clarmso did the trick for me (react is at 16.12.0).
I hit this issue. It’s because there’s two versions of react installed. Run an
npm ls react
to see them. I have a version of react specified in my package.json, and looks like gatsby/gatsby-cli 2.18.5 has a different version of react.I learned of the issue through this page.
Still trying to fix the issue…
Another update - we made some updates to
gatsby
to limit projects affected by it - it was published ingatsby@2.19.18
- but it still might require you to reset/deletepackage-lock.json
.If that still doesn’t fix the issue - it’s likely that you have
react
/react-dom
pinned in yourpackage.json
and the version is lower thanreact@16.8.0
- we don’t have fix for that yet but are looking into it as next step - possible workaround is usingyarn
instead ofnpm
for now (not verified).If anyone is interested technical stuff please check comment on the initial Pull Request I tried to get it fixed - https://github.com/gatsbyjs/gatsby/pull/21508#issuecomment-586753917 and the plan right now is to use some bundler (probably
microbundle
) to bundlereact
ingatsby-cli
so it doesn’t try to usereact
fromnode_modules
and will just have this included directly ingatsby-cli
)