NextJS: process.env not available in next.config.js?

Hey, I’m experiencing an odd issue where I’m trying to read environment variables in next.config.js. When I deploy to fly locally it works fine, but when deploying from a pipeline it does not. The env variables are defined in the fly toml config file. (Tried both the [env] and the [build.args] sections).

Any ideas on what I might be missing?

How are you deploying your app? If, for example, you’re using a Dockerfile and a remote builder, you’ll need to make sure that the vars from the[build.args] section are somehow passed to your build process via env vars - they won’t make it there automatically.

If you had some build arg like MY_VAR, you would want to have something like this in the dockerfile:

ARG MY_VAR

ENV MY_VAR=${MY_VAR}

RUN npm run build

If you do this, you’d call fly deploy with fly deploy --remote-only --build-arg MY_VAR=test

Super helpful, thank you!