diff --git a/e2e/node/src/node.test.ts b/e2e/node/src/node.test.ts index e8ed0ee3fd8fb2..c62cf26616c677 100644 --- a/e2e/node/src/node.test.ts +++ b/e2e/node/src/node.test.ts @@ -108,7 +108,16 @@ describe('Node Applications', () => { `apps/${nodeapp}/src/additional-main.ts`, `console.log('Hello Additional World!');` ); - updateFile(`apps/${nodeapp}/src/main.ts`, `console.log('Hello World!');`); + updateFile( + `apps/${nodeapp}/src/main.ts`, + `console.log('Hello World!'); + console.log('env: ' + process.env['NODE_ENV']); + ` + ); + // deleting `NODE_ENV` value, so that it's `undefined`, and not `"test"` + // this simulates a real behaviour of running node outside on this e2e test + delete process.env.NODE_ENV; + await runCLIAsync(`build ${nodeapp}`); checkFilesExist( @@ -119,6 +128,7 @@ describe('Node Applications', () => { cwd: tmpProjPath(), }).toString(); expect(result).toContain('Hello World!'); + expect(result).toContain('env: development'); const additionalResult = execSync( `node dist/apps/${nodeapp}/additional-main.js`, diff --git a/packages/esbuild/src/executors/esbuild/esbuild.impl.ts b/packages/esbuild/src/executors/esbuild/esbuild.impl.ts index 872d35b1a771b7..239b74828bd209 100644 --- a/packages/esbuild/src/executors/esbuild/esbuild.impl.ts +++ b/packages/esbuild/src/executors/esbuild/esbuild.impl.ts @@ -41,7 +41,7 @@ export async function* esbuildExecutor( _options: EsBuildExecutorOptions, context: ExecutorContext ) { - process.env.NODE_ENV ??= context.configurationName; + process.env.NODE_ENV ??= context.configurationName ?? 'production'; const options = normalizeOptions(_options, context); if (options.deleteOutputPath) removeSync(options.outputPath); diff --git a/packages/js/src/executors/node/node.impl.ts b/packages/js/src/executors/node/node.impl.ts index 5571eab8e47ab7..d22b07bfe86d1b 100644 --- a/packages/js/src/executors/node/node.impl.ts +++ b/packages/js/src/executors/node/node.impl.ts @@ -36,6 +36,7 @@ export async function* nodeExecutor( options: NodeExecutorOptions, context: ExecutorContext ) { + process.env.NODE_ENV ??= context?.configurationName ?? 'development'; const project = context.projectGraph.nodes[context.projectName]; const buildTarget = parseTargetString( options.buildTarget,