Skip to content

Fixing how define are applied by wrangler #10983

@vicb

Description

@vicb

The wrangler configuration has defines that should be applied by ESBuild bundling:

However they are only applied when process.env.NODE_ENV is defined at build time:

...(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,
},
}),

That is process.env.NODE_ENV && gates too many values.

This was fixed in #7932 and further reverted in #7967 because the initial PR lacks tests.

We should re-introduce the initial PR with tests

Metadata

Metadata

Assignees

Labels

bugSomething that isn't workingwranglerRelating to the Wrangler CLI tool

Type

No type

Projects

Status

Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions