zeKoko zeKoko - 1 month ago 14
Javascript Question

React Hot Module Reloader preventing mocha tests from running

I have a React project which is running the

hot module reloader, and all was running fine until I implemented mocha tests.
When I run the tests I get the following error:

throw new Error('locals[0] does not appear to be a
with Hot Module ' + 'replacement API enabled. You should disable
react-transform-hmr in ' + 'production by using
section in Babel
configuration. See the ' + 'example in README:

I have googled this, and found some information mentioning moving the hot module reloading setup out of the
file and into the Webpack config, which I did, and the tests ran fine, but then the Hot Module Reloading wasn't working.

After playing around, and not getting both to work together, I have reverted and thought I would ask for some help as I am truly stuck. Any ideas what I can do?

My babel config is as follows:

"presets": ["react", "es2015", "stage-1"],
"env": {
"development": {
"plugins": [
["react-transform", {
"transforms": [{
"transform": "react-transform-hmr",
"imports": ["react"],
"locals": ["module"]
}, {
"transform": "react-transform-catch-errors",
"imports": ["react", "redbox-react"]
"production": {
"plugins": [

And my webpack config is as follows:

module: {
loaders: [
// js
test: /\.js$/,
loaders: ['babel'],
include: path.join(__dirname, 'client')

Thank you :)


Got this working with the following in the package.json:

"test": "export NODE_ENV=testing|| set NODE_ENV=testing&& mocha --compilers js:babel-core/register --require ./tests/test-helper.js \"./tests/**/*@(.js|.jsx)\"",

This was taken from here.