-
Notifications
You must be signed in to change notification settings - Fork 761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 BUG: process.env.NODE_ENV
is not set to production
by default
#7886
Comments
# wrangler.toml
[vars]
NODE_ENV = "production" Makes See https://developers.cloudflare.com/workers/runtime-apis/nodejs/process/#processenv for details
I am not sure what |
Is it even possible to set the In my specific case, Vike shows a warning if it isn't
This is where Vike reads |
You can have Ideally we should support defining |
Yes, ideally wrangler should automatically set
👍 We'll try that in our |
There are internal discussion around this - stay tuned. I was looking at out code and what we are supposed to do is to set |
Maybe it's an issue on our side though, is there any way I can have a look at the generated worker code? That would help a ton. Even better would be able to modify it and then run this modified version. |
No, it's a few issues on wrangler side. We have this code: workers-sdk/packages/wrangler/src/deployment-bundle/bundle.ts Lines 425 to 436 in 248bdb2
There are a few issues here:
I believe 1 and 2 could be fixed via: // 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)
const runtimeNodeEnv = process.env["NODE_ENV" + ""];
const buildOptions = {
// ...
define: {
...(defineNavigatorUserAgent ? { "navigator.userAgent": `"Cloudflare-Workers"` } : {}),
...(runtimeNodeEnv ? {"process.env.NODE_ENV": `"${runtimeNodeEnv}"`} : {}),
...(nodejsCompatMode === "legacy" ? { global: "globalThis" } : {}),
...define,
}, Not sure how to fix 3. @penalosa or @petebacondarwin would you have time to take a look or find someone that can? |
process.env.NODE_ENV
is null
but should be 'production'
instead.process.env.NODE_ENV
process.env.NODE_ENV
process.env.NODE_ENV
I can confirm it's a wrangler bug: it replaces |
@brillout you should be able to get Wrangler to statically replace You can also use the define config, if you'd prefer (note the extra quotes, as it's a JSON encoded value): [define]
"process.env.NODE_ENV" = "'production'" @vicb I don't think (3) is accurate—this seems to work for me even with |
process.env.NODE_ENV
process.env.NODE_ENV
is not set to production
by default
@penalosa do you use the global or |
I can confirm that the global works but not the import 🚨 So I think we need to fix 1 - 4 |
Which Cloudflare product(s) does this pertain to?
Wrangler
What versions are you using?
3.102.0 [Wrangler]
What operating system and version are you using?
Ubuntu 24.04.1
Please provide a link to a minimal reproduction
No response
Describe the Bug
If I set the following:
Then I expect wrangler to replace
process.env.NODE_ENV
with'production'
. It's a ubiquitous JavaScript convention.I also tried the following, but it doesn't work either.
I can't dig why it doesn't work as it doesn't seem possible to inspect the worker code as per #7885.
Please provide any relevant error logs
No response
The text was updated successfully, but these errors were encountered: