diff --git a/lib/EnvironmentPlugin.js b/lib/EnvironmentPlugin.js index ad8d57336cd..baa9c0af684 100644 --- a/lib/EnvironmentPlugin.js +++ b/lib/EnvironmentPlugin.js @@ -7,6 +7,9 @@ const DefinePlugin = require("./DefinePlugin"); +const needsEnvVarFix = ["8", "9"].indexOf(process.versions.node.split(".")[0]) >= 0 && + process.platform === "win32"; + class EnvironmentPlugin { constructor(keys) { if(Array.isArray(keys)) { @@ -23,6 +26,13 @@ class EnvironmentPlugin { apply(compiler) { const definitions = this.keys.reduce((defs, key) => { + // TODO remove once the fix has made its way into Node 8. + // Work around https://github.com/nodejs/node/pull/18463, + // affecting Node 8 & 9 by performing an OS-level + // operation that always succeeds before reading + // environment variables: + if(needsEnvVarFix) require("os").cpus(); + const value = process.env[key] !== undefined ? process.env[key] : this.defaultValues[key]; if(value === undefined) { diff --git a/lib/node/NodeTargetPlugin.js b/lib/node/NodeTargetPlugin.js index 28ed5db8373..ac2f05a5504 100644 --- a/lib/node/NodeTargetPlugin.js +++ b/lib/node/NodeTargetPlugin.js @@ -6,9 +6,11 @@ const ExternalsPlugin = require("../ExternalsPlugin"); +const builtins = require("module").builtinModules || Object.keys(process.binding("natives")); + class NodeTargetPlugin { apply(compiler) { - new ExternalsPlugin("commonjs", Object.keys(process.binding("natives"))).apply(compiler); + new ExternalsPlugin("commonjs", builtins).apply(compiler); } }