c0nf1den71al/Antimatter

Production build cannot access next environment variables in client side components.

Closed this issue · 1 comments

The production build of Antimatter cannot fetch data from the API due to the environment variable NEXT_PUBLIC_ANTIMATTER_API_URL not being exposed to client side components.

This behaviour is not observed when running the application in dev mode and I think it's due to the variable not being set when the application is compiled.

I have attempted to set the variable as an ARG within the Dockerfile using the following:

ARG NEXT_PUBLIC_ANTIMATTER_API_URL=$ANTIMATTER_API_URL

However, this does not appear to work.

I have attempted to use NextJS Route Handlers to server the environment variable from a server-sider perspective, however, I couldn't get this to work either.

This might be due to the fetch API being inside the useEffect hook, however, I am not sure. Can someone please look into how to resolve this issue please.

Thanks,
J

I have managed to get around this issue by using NextJS Route Handlers as a bridge between the client-side application and the Express API.

Perhaps there is a better way to do this but this works for now 🤷‍♂️