1

I have problem with acces the .env variables. In my Vite cli project I'v added .env variables:

VITE_SOME_KEY = 123

and then in js file:

console.log(import.meta.env.DEV); 
console.log(import.meta.env.VITE_SOME_KEY);

It's working after build and serve. But during development (npm run vite) i have problem:

Module "process" has been externalized for browser compatibility. Cannot access "process.env" in client code.

I check all documentation from vite enviroments but I don't understand how to use .env during development localy

1 Answer 1

0

You need to prefix your custom environment variables with VITE_ to make them available in your code. For example, if you want to use a variable named DEV, you need to define it as DEV in your .env file or in your system.

console.log(import.meta.env.VITE_DEV); console.log(import.meta.env.VITE_SOME_KEY);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.