react-webpack-generators / generator-react-webpack

Yeoman generator for ReactJS and Webpack
http://newtriks.com/2013/12/31/automating-react-with-yeoman-and-grunt/
MIT License
2.87k stars 356 forks source link

Cannot use modules that import `config` in my tests #197

Closed dedan closed 8 years ago

dedan commented 8 years ago

I have one reducer function in which I import the environment specific config object via import {config} from 'config'. This works without problems when using the dev or dist environment, for example in the webpack-dev-server that I start with npm start. But I run into a problem when I import this reducer function in a test.

> mocha --compilers js:babel-core/register --recursive

module.js:339
    throw err;
    ^

Error: Cannot find module 'config'
    at Function.Module._resolveFilename (module.js:337:15)
    at Function.Module._load (module.js:287:25)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)

How do people usually handle things that depend on the webpack build specifics?

weblogixx commented 8 years ago

Hi @dedan,

we are using webpack to include the configuration (it is set as an alias in the webpack configuration). This means you will need to use webpack to use it correctly. However, you could also include it like a regular es2015 import:

// webpack, available from anywhere:
import config from 'config';

// without webpack:
import config from '../full/path/to/src/config/DEV-OR-LIVE';

Does this help?

dedan commented 8 years ago

Thank you for this explanation. In the end I solved it by switching to the Karma test runner.