1

I'm referring to the documentation about environment variables in vue cli 3.

I'm able to set it up and get simple variables to show up but my url in the .env file doesn't show up.

Contents of the .env file:

FOO=bar
VUE_APP_SECRET=secret
API_URL="https://staging.something.org"

Here is how I'm viewing the env:

console.log(process.env)
BASE_URL: "/"
NODE_ENV: "development"
VUE_APP_SECRET: "secret"

The API_URL is not visible, am I doing something wrong?

2 Answers 2

3

Refer to the documentation.

Only variables that start with VUE_APP_ will be statically embedded into the client bundle with webpack.DefinePlugin. You can access them in your application code:

Your VUE_APP_SECRET is accessible because it's prefixed with VUE_APP_. Use VUE_APP_API_URL instead of API_URL to access it in your frontend.

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

1 Comment

Thank you so much, I just missed that somehow in the doc.
1

Since CLI 3, Vue recognizes variables in dotenv only when adding the prefix VUE_APP_

When making changes, restart CLI.

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

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.