Skip to content

Can't access Environment Variables in Loader via import.meta.env... #13471

Discussion options

You must be logged in to vote

This is just a feature of Vite.

To prevent accidentally leaking env variables to the client, only variables prefixed with VITE_ are exposed to your Vite-processed code.

Vite is the one providing the import.meta.env API and your route module is the "Vite-processed code" in question here. In production, import.meta.env may not be available on your chosen runtime (it's not in Node as of yet), so this may end up failing there. You should rely on the env system that will be available in your runtime, which will likely be process.env for most projects.

This is where the automatic code-splitting comes into play. You can use server-only APIs safely in your loader, as that will be removed from …

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
5 replies
@nikolailehbrink
Comment options

@lambdalisue
Comment options

@nikolailehbrink
Comment options

@chopfitzroy
Comment options

@nikolailehbrink
Comment options

Comment options

You must be logged in to vote
1 reply
@nikolailehbrink
Comment options

Answer selected by nikolailehbrink
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants