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

ian_h's avatar
Level 20

Laravel Mix - VueJS - MIX_ env vars undefined

Hi all..

I'm coding a hybrid Laravel/VueJS site but have come across a production env issue that I wondered if it'd been experienced before? This is a brand new site using the latest versions of things (only started a couple of weeks ago).

I have 2 values in my .env file prefixed with MIX_. When I run this locally, as a dev environment, it works fine. When I build it (front end) locally as production, it works fine.

The site is pushed through my Gitlab instance and build pipeline which creates the .env file in a docker container from a Gitlab CI/CD variable. This works fine as when I login to the container, I can see the relevant values in the .env file.

Looking at the compiled app.js file, I can see there where it references both of the env vars via process.env.MIX_VAR_NAME, however, when trying to access these in the VueJS component, they're undefined (console.log() shows this and the code that uses them fails).

Has anyone else experienced this or have any idea why this might be?

Laravel mix is v5.0.5

Laravel is 7.27.0

Vue is 2.6.11

Cheers..

Ian

0 likes
3 replies
nai's avatar

Hey, did you solved this? I have same issue in docker

Shawki's avatar

DId anyone get the solution for Prod env. ? I also faced this

eranda's avatar

I added require('dotenv').config(); code in webpack.mix.js file before mix object. The problem resolved.

Please or to participate in this conversation.