Skip to content

handling of process.env.NODE_ENV default in wrangler #10984

@vicb

Description

@vicb

Prerequisite: #10983

As of today process.env.NODE_ENV is left undefined by wrangler unless it is an explicitly set environment variable at build time or there is a define in the wrangler config:

...(process.env.NODE_ENV && {
define: {
...(defineNavigatorUserAgent
? { "navigator.userAgent": `"Cloudflare-Workers"` }
: {}),
// use process.env["NODE_ENV" + ""] so that esbuild doesn't replace it
// when we do a build of wrangler. (re: https://github.com/cloudflare/workers-sdk/issues/1477)
"process.env.NODE_ENV": `"${process.env["NODE_ENV" + ""]}"`,
...define,
},
}),

However many packages are optimized for prod when process.env.NODE_ENV === "production".

We should align with what Vite does:

  • default to "production" for wrangler deploy/upload
  • default to "development" for wrangler dev

Note that the default should still be overridable using a build time process.env.NODE_ENV (which include .env* files) and wrangler define config.

There are a couples of existing issues that would be solved:

ref: internal discussion1, discussion 2

Metadata

Metadata

Assignees

Labels

caretakingPriority for caretaking

Type

No type

Projects

Status

Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions