NODE_ENV is always "development" regardless of my secrets and configuration

Hey, there! I’m having trouble setting my NODE_ENV to “production” in https://remix-forms.fly.dev.

The command I’m using to start the server in my Dockerfile is CMD ["npm", "run", "start"] and in my package.json’s script section I have "start": "cross-env NODE_ENV=production remix-serve build". I think this should be enough to set it to “production”, right?

I also have ENV NODE_ENV=production in my Dockerfile. Also, I have the following in my fly.toml file:

[env]
  NODE_ENV = "production"

Finally, I have created a secret with fly secrets set NODE_ENV=production.

But still when I console.log(process.env.NODE_ENV) it returns development.

Does anyone know how to help me with that? Thanks!

Sounds like that’s set at build time. But e.g Fly’s secrets apply at runtime. So when the build happens, the value is ‘development’.

Based on:

Thanks for finding this issue, @greg!

I have no problem with setting this at build time, though. I just need to know how to do it. Shouldn’t the things I have on the Dockerfile or the fly.toml file make it set to production in build time? Or am I missing something here?

1 Like

No problem.

My understanding is that the [env] part of the fly.toml and the fly secrets are both used at runtime. Of course the [env] would be used for any not-secret env values that don’t need to be stored encrypted.

The Dockerfile would be where I think the build-time variables need to be set. Before any build command is run. You have ARG for build-time only ones, or ENV for ones used during the build and the resulting image.

It’s possible that NODE_ENV is being treated differently by Remix as that has its own meaning, unlike CUSTOM_NAME.

Another thing to check: that NODE_ENV is being set before the build command is run in the Dockerfile e.g here in one of their demo stacks it’s near the first thing.

1 Like

i’m just trying to switch from heroku, so i use the heroku buildpack heroku/pack:20 flyctl set for me, but i can not get rid of the message during build [Warning: Skip pruning because NODE_ENV is not 'production'.] (and the HUGE image size) - i’ve set NODE_ENV in fly.toml && with flyctl secrets set. what should I do?

I have seen this issue and tried secrets and setting the [env] in the toml but it didn’t pick it up. What resolved it for me was doing the deploy with the --remote-only flag.

$ flyctl deploy --remote-only

thanks, i’ve tried that now - but still getting the same results :frowning:

Hi all.
I ran the following and it worked fine:

flyctl deploy --build-arg NODE_ENV=production --remote-only

[INFO] Successfully pruned devdependencies!

I setted [build.args] section in fly.toml and it worked too

2 Likes