From 7033a916af24954c93b22ce4f2d14778c1ea11f1 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Wed, 20 Jan 2021 19:25:42 +0800 Subject: [PATCH] fix: discard `NODE_ENV` when installing project dependencies Avoid empty `node_modules` when the user has set `NODE_ENV` to `production` in the shell environment. In the long run we should have a more comprehensive preflight check for execution environment though. --- packages/@vue/cli/lib/util/ProjectPackageManager.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/@vue/cli/lib/util/ProjectPackageManager.js b/packages/@vue/cli/lib/util/ProjectPackageManager.js index b91f30f29d..4ee1a2d26c 100644 --- a/packages/@vue/cli/lib/util/ProjectPackageManager.js +++ b/packages/@vue/cli/lib/util/ProjectPackageManager.js @@ -347,8 +347,14 @@ class PackageManager { } async runCommand (command, args) { + const prevNodeEnv = process.env.NODE_ENV + // In the use case of Vue CLI, when installing dependencies, + // the `NODE_ENV` environment variable does no good; + // it only confuses users by skipping dev deps (when set to `production`). + delete process.env.NODE_ENV + await this.setRegistryEnvs() - return await executeCommand( + await executeCommand( this.bin, [ ...PACKAGE_MANAGER_CONFIG[this.bin][command], @@ -356,6 +362,10 @@ class PackageManager { ], this.context ) + + if (prevNodeEnv) { + process.env.NODE_ENV = prevNodeEnv + } } async install () {