fly [env] not loaded by vite

My expectation was that Vite would make fly’s [env] variables available in import.meta.env as long as its prefixed with “VITE_”.

This works as expected with secrets, but not with [env].
I’m looking for guidance or better understanding of possible causes.

fly.toml

[env]
  VITE_VAR = 'some-var'

fly secrets

VITE_SECRET_VAR=secret

process.env correctly has both.

{
  ...
  VITE_SECRET_VAR: 'secret',
  VITE_VAR: 'some-var',
  ...
}

BUT import.meta.env only contains the variable from secret, but not from [env]

{
  VITE_SECRET_VAR: 'secret'
}

Would appreciate any clue here.
Thanks in advance!

I think it’s because [env] are RUNTIME. Hence why vite doesn’t have the [env] variables when it reloads the values at buildtime.

You gave me the right clue.

I ended up using [build.args] and passing it into docker to access variables during build time
fly.toml

[build]
  [build.args]
    LOCATION='some-location'

Dockerfile

ARG LOCATION
ENV VITE_LOCATION=$LOCATION

thanks for the help!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.