Error during build: `WebpackError: Could not find "store"`
See original GitHub issueDescription
I use redux
to add a global state to my gatsby website. It works but the build failed:
WebpackError: Could not find "store" in either the context or props of "Connect(DefaulLayout)". Either wrap the root component in a <Provider>, or explicitly pass "store" as a prop to "Connect(DefaulLayout)".
Environment
Gatsby version: 1.9.127 Node.js version: 9.2.0 Operating System: Ubuntu 17.10
File contents
I took this 2 files from https://github.com/gatsbyjs/gatsby/tree/master/examples/using-redux:
gatsby-browser.js
:
import React from 'react'
import { Router } from 'react-router-dom'
import { Provider } from 'react-redux'
import createStore from './src/state/createStore'
exports.replaceRouterComponent = ({ history }) => {
const store = createStore()
const ConnectedRouterWrapper = ({ children }) => (
<Provider store={store}>
<Router history={history}>{children}</Router>
</Provider>
)
return ConnectedRouterWrapper
}
gatsby-ssr.js
:
import React from 'react'
import { Provider } from 'react-redux'
import { renderToString } from 'react-dom/server'
import createStore from './src/state/createStore'
exports.replaceRenderer = ({ bodyComponent, replaceBodyHTMLString }) => {
const store = createStore()
const ConnectedBody = () => (
<Provider store={store}>
{bodyComponent}
</Provider>
)
replaceBodyHTMLString(renderToString(<ConnectedBody/>))
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
reactjs - Could not find "store" in the context of "Connect(App)".
During the npm test, I get the following error: FAIL src/App.test.js × renders App (74 ms). ○ renders App **Could not find "store"...
Read more >Troubleshooting Common Errors - Gatsby
If you see errors about not being able to find a resource in the cache it may be enough to clear your cache...
Read more >[Support Guide] Netlify app builds locally but fails on deploy ...
Netlify build failed with webpack error - css-syntax-error (unknown word) ... Project builds locally but get "WebpackError: TypeError: Cannot read property ...
Read more >[Solved]-Syntax in crac-webpack-rewired to solve webpack polyfills ...
[Solved]-Syntax in crac-webpack-rewired to solve webpack polyfills error-Reactjs ... loading is complete · Could not find "store" in the context of "Connect ...
Read more >Changelog - Cypress Documentation
Fixed a regression introduced in Cypress 12 where cy.get() would ignore a null ... rejection would display an incomplete error message in the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ohh ok I think
gatsby-plugin-glamor
means you’re running in to #2005. Thanks for creating the example repo 😃Until there’s a better way of handling this, you’ll probably need to manually reimplement the
gatsby-plugin-glamor
code in yourgatsby-ssr.js
. Check out the examples in the linked issue.Hmm yeah, really need to add the check described in #2005