babel-preset-react-app无法获取环境变量 [英] babel-preset-react-app not picking up environment variables

查看:533
本文介绍了babel-preset-react-app无法获取环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法编译./src/index.js模块构建失败:错误:正在使用 babel-preset-react-app 要求您指定 NODE_ENV BABEL_ENV 环境变量.有效值为发展",测试"和生产".而是收到:未定义".(尽管加工预设:"C:\ Users \ mitch \ OneDrive \ Development \ Git \ react-seed \ node_modules \ babel-preset-react-app \ index.js")在Array.map(本地)上

Failed to compile ./src/index.js Module build failed: Error: 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". (While processing preset:"C:\Users\mitch\OneDrive\Development\Git\react-seed\node_modules\babel-preset-react-app\index.js") at Array.map (native)

自从更新我的react-app以来,无论尝试设置环境还是环境变量的怪异和奇妙的方式有多少,我都会不断收到上述错误,我什至会在通过'create-react创建的新应用程序中获取此错误-app'脚本-我明显在做什么错了?

I keep getting the above error no matter how many weird and wonderful ways I try to set either the environment or the environment variables since updating my react-app and I even get this on a fresh app created from the 'create-react-app' scripts - What am I clearly doing wrong?

推荐答案

我在我的package.json中完成它:

I do it in my package.json:

{
  "scripts": {
    "build": "NODE_ENV=development babel src -d lib",
    "build-prod": "NODE_ENV=production babel src -d lib"
  }
}

这篇关于babel-preset-react-app无法获取环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆