I followed the instructions over at the official docs; my app was working just fine in chrome, pointing to localhost:3000
. However, now Im running into an issue, because it seems that if a browser doesnt have Redux extension, it won't work. According to the docs, I have written out:
import { createStore, applyMiddleware, compose } from "redux";
import thunk from "redux-thunk";
import rootReducer from "./reducers"; //we dont have to put index.js because its called index.js
const initialState = {};
const middleware = [thunk];
const store = createStore(
rootReducer,
initialState,
compose(
applyMiddleware(...middleware),
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
)
); //spread operator '...'
export default store;
Am I missing something? It seems that others are running into the same issue and solutions seem unique per codebase.
Edit: I've also tried this solution, but Im getting an error TypeError: _store__WEBPACK_IMPORTED_MODULE_12__.default.dispatch is not a function
Edit 2: In chrome incognito mode (where the redux dev tool extension is not enabled), I run into the error,
TypeError: Cannot read property 'apply' of undefined
(anonymous function)
C:/Users/MishaFresh/Desktop/mern-app/MERN_app/client/node_modules/redux/es/redux.js:575
572 |
573 | return funcs.reduce(function (a, b) {
574 | return function () {
> 575 | return a(b.apply(void 0, arguments));
576 | };
577 | });
578 | }
Likewise same error in Firefox.
My package.json
:
"scripts": {
"client-install": "npm install --prefix client",
"start": "node server.js",
"server": "nodemon server.js",
"client": "npm start --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\"",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
},
Edit 3:
New error after implementing the suggestion below:
TypeError: _store__WEBPACK_IMPORTED_MODULE_12__.default.dispatch is not a function
Module../src/App.js
C:/Users/Me/Desktop/my-app/app/client/src/App.js:40
37 | //decode it
38 | const decoded = jwt_decode(localStorage.jwtToken);
39 | //set user and isAuthenticated
> 40 | store.dispatch(setCurrentUser(decoded));
| ^ 41 |
42 | //check for expired token
43 | const currentTime = Date.now() / 1000;