【问题标题】:You should disable react-transform-hmr in production by using `env` section in Babel configuration您应该使用 Babel 配置中的 `env` 部分在生产中禁用 react-transform-hmr
【发布时间】:2016-10-28 20:01:26
【问题描述】:

我正在使用 babel-cli 进行 jsx 和 es6 功能的转译

我改变了我的构建命令

来自

"build": "node build",

"build": "babel-node build",

之前一切正常

但是当我运行构建命令时,我得到了这个错误

错误:locals[0] 似乎不是启用了热模块替换 API 的 module 对象。您应该使用 Babel 配置中的 env 部分在生产中禁用 react-transform-hmr。请参阅自述文件中的示例:https://github.com/gaearon/react-transform-hmr

另见截图

所以我应该在 Babel 配置中使用 env 部分在生产中禁用 react-transform-hmr

这是我的 .babelrc,就像说明一样

{
  "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"]
      ]
    }
  }
}

我做错了什么?有什么推荐吗?

【问题讨论】:

标签: node.js reactjs babeljs


【解决方案1】:

我必须将 NODE_ENV=production 添加到命令中

"build": "NODE_ENV=production babel-node build"

【讨论】:

  • 这根本不能解决问题,你只是通过不构建开发环境来解决它。
猜你喜欢
  • 2017-09-25
  • 2023-01-05
  • 1970-01-01
  • 2021-09-30
  • 2019-01-07
  • 1970-01-01
  • 2018-01-05
  • 2018-04-21
  • 1970-01-01
相关资源
最近更新 更多