小编Mig*_*gel的帖子

比较环境变量和常量时,字符串比较在Javascript中不起作用

我们有一个使用CRA 1.x创建的简单React应用程序。

We installed dotenv to use environment variables on the project and our variables are included on the .env and .env.development files like this:

.env

REACT_APP_LOGGER=LOGGER
Run Code Online (Sandbox Code Playgroud)

.env.development

REACT_APP_LOGGER=NO_LOGGER
Run Code Online (Sandbox Code Playgroud)

Then in the code we have this logic:

if(process.env.REACT_APP_LOGGER === "LOGGER") {
    // do something
}
Run Code Online (Sandbox Code Playgroud)

On local builds with webpack 4 in development mode the if is true, and on production mode is false.

But on azure, in both cases is false

process.env.REACT_APP_LOGGER === "LOGGER" // false
Run Code Online (Sandbox Code Playgroud)

We have checked …

javascript environment-variables node.js

6
推荐指数
2
解决办法
870
查看次数