banderson / generator-redux

CLI tools for Redux: next-gen functional Flux/React with devtools
252 stars 36 forks source link

[Resolves #10] Fresh installs have a Uncaught TypeError when using 'npm start' #15

Closed SpencerCDixon closed 8 years ago

SpencerCDixon commented 8 years ago

Updated configure store to use new redux-devtools configuration. Fixes problem of 'Uncaught TypeError: store.getState is not a function'

It would work using node server.js but with running npm start or DEBUG=true npm start the app was failing. Updating the store configuration using their readme seemed to fix it for me locally.

I'm very skeptical as to why moving it from a require to an import actually fixed the problem. Don't know enough about Node/ES6 yet to know why though...

When the generator runs on a fresh install this is what the configureStore.js looks like:

import {createStore, applyMiddleware, combineReducers, compose} from 'redux';
import thunkMiddleware from 'redux-thunk';
import * as reducers from '../reducers/index';

let createStoreWithMiddleware;

// Configure the dev tools when in DEV mode
if (__DEV__) {
  let {devTools, persistState} = require('redux-devtools');
  createStoreWithMiddleware = compose(
    applyMiddleware(thunkMiddleware),
    devTools(),
    persistState(window.location.href.match(/[?&]debug_session=([^&]+)\b/)),
    createStore
  );
} else {
  createStoreWithMiddleware = applyMiddleware(thunkMiddleware)(createStore);
}

const rootReducer = combineReducers(reducers);

export default function configureStore(initialState) {
  return createStoreWithMiddleware(rootReducer, initialState);
}

Seems like the real issue is it's just not applying the template properly. Its adding createStore as an argument to compose which is just wrong.

SpencerCDixon commented 8 years ago

After writing tests to confirm the file was being copied over it appeared that there was somewhat of an error with this line being copied over: persistState(window.location.href.match(/[?&]debug_session=([^&]+)\b/))

The \b threw errors in my tests so I had to escape it twice. I ran npm link to symlink the generator and use my own local version and it copied over the configureStore file fine. Is there something that needs to be done for Yeoman to use the latest version of the templates?

banderson commented 8 years ago

:+1: thanks man!