【react】解决babel-preset-react-app报错

报错:
Using babel-preset-react-app requires that you specify NODE_ENV or BABEL_ENV environment variables. Valid values are “development”, “test”, and “production”. Instead, received: undefined.
方式一:

  • 弊端:开发时,一些报错、警告会受影响,如props检验警告,不能再控制台打印;
// package.json 
"babel": {
    "presets": [
      [
        "babel-preset-react-app",//关闭使用开发环境
        false
      ],
      [
        "babel-preset-react-app/prod",//开启使用生产环境编译
        {
          "runtime": "automatic"// 可以不用单独在组件中引入React
        }
      ]
    ]
  }

方式二:直接删除eslintConfig

// package.json 
-  "eslintConfig": {
-    "extends": [
-      "react-app/prod",//开启生产环境检查
-      "react-app/jest"
-    ]
-  },
// "browserslist":{
 "babel": {
  "presets": [
    [
      "babel-preset-react-app"
    ]
  ]
}

你可能感兴趣的:(react,react.js,javascript,前端)