zeKoko zeKoko - 3 months ago 25
Javascript Question

React Hot Module Reloader preventing mocha tests from running

I have a React project which is running the

react-transform-hmr
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
module
object
with Hot Module ' + 'replacement API enabled. You should disable
react-transform-hmr in ' + 'production by using
env
section in Babel
configuration. See the ' + 'example in README:
https://github.com/gaearon/react-transform-hmr');


I have googled this, and found some information mentioning moving the hot module reloading setup out of the
.babelrc
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": [
["transform-object-rest-spread"],
["transform-react-display-name"],
["react-transform", {
"transforms": [{
"transform": "react-transform-hmr",
"imports": ["react"],
"locals": ["module"]
}, {
"transform": "react-transform-catch-errors",
"imports": ["react", "redbox-react"]
}]
}]
]
},
"production": {
"plugins": [
["transform-object-rest-spread"],
["transform-react-display-name"]
]
}
}
}


And my webpack config is as follows:

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


Thank you :)

Answer

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.

Comments