Мое приложение next.js redux прекрасно работает в режиме разработки, но когда я запускаю npm run build
и запускаю приложение в производственном режиме, оно регистрирует эту ошибку;
{ Invariant Violation: Could not find "store" in the context of "Connect(Form(LoginForm))". Either wrap the root
component in a <Provider>, or pass a custom React context provider to <Provider> and the corresponding React context consumer to Connect(Form(LoginForm)) in connect options.
https://github.com/jankoboz/WeGhana-property
Я удалил LoginForm, но на этот раз выдает ту же ошибку, что и RegisterForm, и также на этот раз он выдает такую же ошибку msg с другим компонентом с использованием метода connect.
// createStore.js
import Immutable from 'immutable'
import thunkMiddleware from 'redux-thunk'
import { createLogger } from 'redux-logger'
import { createStore, applyMiddleware, compose } from 'redux'
import config from 'config'
import rootReducer from './reducers/index.js'
function createMiddlewares ({ isServer }) {
let middlewares = [
thunkMiddleware
]
if (config.env === 'development' && typeof window !== 'undefined') {
middlewares.push(createLogger({
level: 'info',
collapsed: true,
stateTransformer: (state) => {
let newState = {}
for (let i of Object.keys(state)) {
if (Immutable.Iterable.isIterable(state[i])) {
newState[i] = state[i].toJS()
} else {
newState[i] = state[i]
}
}
return newState
}
}))
}
return middlewares
}
function immutableChildren (obj) {
let state = {}
Object.keys(obj).forEach((key) => {
state[key] = Immutable.fromJS(obj[key])
})
return state
}
export default (initialState = {}, context) => {
let { isServer } = context
let middlewares = createMiddlewares({ isServer })
let state = immutableChildren(initialState)
return createStore(
rootReducer,
state,
compose(applyMiddleware(...middlewares))
)
}
// _app.js
import withRedux from 'next-redux-wrapper'
import { withRouter } from 'next/router'
import { Provider } from 'react-redux'
import App, { Container } from 'next/app'
import { checkForPopup } from "./helpers/popup.js";
import createStore from './redux/createStore.js'
class MyApp extends App {
static async getInitialProps ({ Component, ctx }) {
return {
pageProps: Component.getInitialProps
? await Component.getInitialProps(ctx)
: {}
}
}
render() {
const { Component, pageProps, store, router } = this.props
return (
<Container>
<Provider store={store}>
<Component router={router} {...pageProps} />
</Provider>
</Container>
);
}
componentDidMount() {
checkForPopup();
}
}
export default withRedux(createStore)(
withRouter(MyApp)
)