Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vincent15000's avatar

Impossible to use process.env.CONSTANT

Hello,

I'm using VueJS 3 and when I try to use process.env.CONSTANT to get a value from the environment variables, I have an error message saying that process does not exist.

I don't understand why I have this error because with VueJS version 3 I don't need to use the dotenv plugin.

Do you have a valid example to show me ?

Thank you very much ;).

Vincent

0 likes
8 replies
vincent15000's avatar

@bobbybouwmann I just read the link ... there is a warning.

https://cli.vuejs.org/guide/mode-and-env.html#environment-variables

WARNING
Do not store any secrets (such as private API keys) in your app!
Environment variables are embedded into the build, meaning anyone can view them by inspecting your app's files.

Does it mean that no secret key should be written in the .env file ? I thought it was like in Laravel. So I have a new question : where is it possible de save securely the secret keys in VueJS ?

bobbybouwmann's avatar
Level 88

@vincent15000 The .env file is fine as long as you encrypt the values. Vue runs in the frontend so there is no server in between that can securely get those values. Instead, you need to use a backend to access things behind a security token. You can use environment keys for different things, except for private tokens like the warning mentions.

Since Vue 3 you need to prefix them with VUE_APP_.

1 like
vincent15000's avatar

@MaverickChan Just Laravel with VueJS. That's why I thought it was automatic.

@bobbybouwmann According to the documentation, VUE_APP_ prefix is not obligatory. But I have difficulty to understand the difference with the other types of variables. Would the other types not embedded in the build ?

Niush's avatar

May be try adding this at top of webpack.mix.js

require('dotenv').config();
1 like

Please or to participate in this conversation.