@@ -393,11 +393,6 @@ export async function bundleWorker(
393393
394394 const unenvResolvePaths = getUnenvResolvePathsFromEnv ( ) ?. split ( "," ) ;
395395
396- // Use `process.env["NODE_ENV" + ""]` to get the runtime value when wranler is executed.
397- // Esbuild would replace `process.env.NODE_ENV` with the value it has when wrangler gets bundled.
398- // See: https://github.com/cloudflare/workers-sdk/issues/1477)
399- const runtimeProcessEnv = process . env [ "NODE_ENV" + "" ] ;
400-
401396 const buildOptions = {
402397 // Don't use entryFile here as the file may have been changed when applying the middleware
403398 entryPoints : [ entry . file ] ,
@@ -427,16 +422,18 @@ export async function bundleWorker(
427422 metafile : true ,
428423 conditions : getBuildConditions ( ) ,
429424 platform : getBuildPlatform ( ) ,
430- define : {
431- ...( defineNavigatorUserAgent
432- ? { "navigator.userAgent" : `"Cloudflare-Workers"` }
433- : { } ) ,
434- ...( runtimeProcessEnv
435- ? { "process.env.NODE_ENV" : `"${ runtimeProcessEnv } "` }
436- : { } ) ,
437- ...( nodejsCompatMode === "legacy" ? { global : "globalThis" } : { } ) ,
438- ...define ,
439- } ,
425+ ...( process . env . NODE_ENV && {
426+ define : {
427+ ...( defineNavigatorUserAgent
428+ ? { "navigator.userAgent" : `"Cloudflare-Workers"` }
429+ : { } ) ,
430+ // use process.env["NODE_ENV" + ""] so that esbuild doesn't replace it
431+ // when we do a build of wrangler. (re: https://github.com/cloudflare/workers-sdk/issues/1477)
432+ "process.env.NODE_ENV" : `"${ process . env [ "NODE_ENV" + "" ] } "` ,
433+ ...( nodejsCompatMode === "legacy" ? { global : "globalThis" } : { } ) ,
434+ ...define ,
435+ } ,
436+ } ) ,
440437 loader : COMMON_ESBUILD_OPTIONS . loader ,
441438 plugins : [
442439 aliasPlugin ,
0 commit comments