Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

You should disable react-transform-hmr in production by using `env` section in Babel configuration

I am using babel-cli for jsx and es6 features to transpile

i have changed my build command

from

"build": "node build",

to

"build": "babel-node build",

Everything was working fine before

But when i run the build command i get this error

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

See the screenshot also

enter image description here

So i should disable react-transform-hmr in production by using env section in Babel configuration

and this is my .babelrc like the instructions

{
  "presets": ["react", "es2015"],
  "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"]
      ]
    }
  }
}

what am i doing wrong? Any recommendation?

like image 896
Koala7 Avatar asked Dec 19 '25 05:12

Koala7


1 Answers

I had to add NODE_ENV=production to the command

"build": "NODE_ENV=production babel-node build"
like image 192
Koala7 Avatar answered Dec 20 '25 22:12

Koala7



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!