Unable to read env variables in react vite project (build using Dockerfile)
//.env file
VITE_DUMMY_KEY_1=1000
VITE_DUMMY_KEY_2=$PORT
VITE_DUMMY_KEY_3=${PORT}
VITE_DUMMY_KEY_4=${{PORT}}
//checking by logging the keys
const k1 = import.meta.env.VITE_DUMMY_KEY_1;
console.log("k1::: ",k1);
const k2 = import.meta.env.VITE_DUMMY_KEY_2;
console.log("k2::: ",k2);
const k3 = import.meta.env.VITE_DUMMY_KEY_3;
console.log("k3::: ",k3);
const k4 = import.meta.env.VITE_DUMMY_KEY_4;
console.log("k4::: ",k4);
27 Replies
Project ID:
N/A
N/A
please send your dockerfile
interesting
enclose your code with triple backticks please
can you share your repo please?
GitHub
GitHub - tonyghouse/memoirist-ui
Contribute to tonyghouse/memoirist-ui development by creating an account on GitHub.
any reason you aren't building with nixpacks?
using nixpacks but due to some dependencies i have to use --legecy-deps commnad so changed deployment to docker
but why variables are not accessible in env
you should really fix the dependency conflicts
used docker for java project there i was able to access variables from railway
so there is no way to access variables in docker?
yes of course there is but that's not the biggest issue here
have you set the variables in your service and can you show me a screenshot of the service variables
okay now fix your dependency conflicts and move back to nixpacks
let me know when that's done
used nix packs but still variables are not accesible
its weird
build is successful app is deployed but variables are not accessible
you've fixed the dependency conflicts?
yes wait its accessible now
able to access variables
seems deployment takes time to go live
have you removed or renamed the dockerfile
deleted the docker file
just nixpacks is used to build
perfect
but why env not worked during docker still bugs me
because you didn't define the variables in the dockerfile, nixpacks does this for you automatically, and that's why I had you move back to nixpacks
is there any documentation or tutorial where we can access variables from railway and set it in during docker file. helpful if you can share if you have
you aren't using a dockerfile anymore?
yes but in future if i need
coz some times i use old libs for the projects there i cant resolve have to go with --legecy-deps command
okay well it's simple enough
let's say you add a service variable
VITE_TEST
= HELLO
you would just have to place ARG VITE_TEST
in your dockerfile under the FROM
line
no no, there is always a better way to resolve peer depsthanks brody
no problem π