From 4f62b4044ca7dd176949e2d9005e189a7d6bc317 Mon Sep 17 00:00:00 2001 From: Adam Stankiewicz Date: Tue, 18 Jul 2023 12:09:21 -0400 Subject: [PATCH] fix: ensure .env.development PORT works (#423) --- lib/scripts/serve.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/scripts/serve.js b/lib/scripts/serve.js index 714ed3d63..40101da42 100644 --- a/lib/scripts/serve.js +++ b/lib/scripts/serve.js @@ -40,13 +40,15 @@ if (isDirectoryEmpty(buildPath)) { console.log(chalk.bold.red(`ERROR: No build found. Please run ${formattedBuildCmd} first.`)); } else { let configuredPort; - let envConfig; try { - envConfig = require(path.join(process.cwd(), 'env.config.js')); - configuredPort = envConfig?.PORT || process.env.PORT; + configuredPort = require(path.join(process.cwd(), 'env.config.js'))?.PORT; } catch (error) { - // pass, consuming applications may not have an `env.config.js` file. This is OK. + // Pass. Consuming applications may not have an `env.config.js` file. This is OK. + } + + if (!configuredPort) { + configuredPort = process.env.PORT; } // No `PORT` found in `env.config.js` and/or `.env.development|private`, so output a warning.