【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.
·
报错:
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"
]
]
}
更多推荐
已为社区贡献3条内容
所有评论(0)