Skip to content

Commit 8da8b93

Browse files
committed
Work around Node environment variable bug
Work around nodejs/node#18463 by detecting the conditions under which the bug occurs and performing a simple operation that resets the error state if necessary.
1 parent e4375f8 commit 8da8b93

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/EnvironmentPlugin.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
const DefinePlugin = require("./DefinePlugin");
99

10+
const needsEnvVarFix = ["8", "9"].indexOf(process.versions.node.split(".")[0]) >= 0 &&
11+
process.platform === "win32";
12+
1013
class EnvironmentPlugin {
1114
constructor(keys) {
1215
if(Array.isArray(keys)) {
@@ -23,6 +26,13 @@ class EnvironmentPlugin {
2326

2427
apply(compiler) {
2528
const definitions = this.keys.reduce((defs, key) => {
29+
// TODO remove once the fix has made its way into Node 8.
30+
// Work around https://github.com/nodejs/node/pull/18463,
31+
// affecting Node 8 & 9 by performing an OS-level
32+
// operation that always succeeds before reading
33+
// environment variables:
34+
if(needsEnvVarFix) require("os").cpus();
35+
2636
const value = process.env[key] !== undefined ? process.env[key] : this.defaultValues[key];
2737

2838
if(value === undefined) {

0 commit comments

Comments
 (0)