Undefined process env node_env: Understanding the Cause

In my code, I utilized a specific method to conditionally set a base path, which functioned correctly in previous projects featuring certain dependencies. However, after updating to the latest version of SvelteKit, this method now only produces unexpected results.
Upon further inspection, I noticed that the updated project lists a particular package as a devDependency, and the script has also been modified. This change is apparent even in other projects with different dependencies, as long as they were created before vite 3.0.
I have consulted the vite documentation to find a solution, but so far, I have not found any relevant information. Even switching from Node v16 to v17 did not help.
My question now is, what has changed, and how can I differentiate between the two modes (development and production) when calling gulp with a variable?

Question:

To manage different builds, it’s necessary to pass a variable while calling gulp. I attempted to set NODE_ENV on my Win7 system as shown in

set NODE_ENV=prod

, and then initiated the process as shown in

gulp

.

The gulpfile contains solely an output.

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

process.env.NODE_ENV
remains undefined consistently.

[23:53:55] Using gulpfile F:DevOpsgulpEnvTestgulpfile.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?

What is the reason behind it? I attempted to use cross-env as well, but it also failed to work.


Solution:

As per the given response, by utilizing

set NODE_ENV=prod

, you are only configuring it within the existing process area.

To assign the variable to the system level, utilize

setx NODE_ENV prod

.

Frequently Asked Questions

Posted in Uncategorized