简体   繁体   English

已设置process.env.NODE_ENV,但仍未定义

[英]process.env.NODE_ENV is set but still undefined

I need to pass a variable when calling gulp, so I one can manage different builds. 我在调用gulp时需要传递一个变量,以便我可以管理不同的构建。 I am on Win7 and tried to set NODE_ENV like set NODE_ENV=prod .. then I start gulp 我Win7上,并试图设置NODE_ENV像set NODE_ENV=prod ..然后我开始gulp

..in the gulpfile there is only a output ..在gulpfile中只有一个输出

var gulp = require('gulp');

gulp.task('default', function() {
    console.log(process.env.NODE_ENV);
});

but process.env.NODE_ENV is always undefined(?) 但是process.env.NODE_ENV始终是未定义的(?)

[23:53:55] Using gulpfile F:\DevOps\gulpEnvTest\gulpfile.js
[23:53:55] Starting 'default'...
undefined
[23:53:55] The following tasks did not complete: default
[23:53:55] Did you forget to signal async completion?

Why is that? 这是为什么? .. I also tried other things like cross-env, but this also does not work. ..我也尝试了诸如cross-env之类的其他方法,但这也不起作用。

According to this answer when using set NODE_ENV=prod you are just setting it in the current process space. 根据此答案 ,使用set NODE_ENV=prod您只是在当前进程空间中进行设置。

You should use setx NODE_ENV prod to set the var to system environment variable level. 您应该使用setx NODE_ENV prod将var设置为系统环境变量级别。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM