question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MIX_ prefixed variable in .env not present in webpack.mix.js

See original GitHub issue
  • Laravel Mix Version: 1.4.2
  • NPM Version: 5.3.0
  • OS: macOS 10.12.6

Description:

I place some variables inside my .env file prefixed with MIX_ as it is stated in documentation (https://laravel.com/docs/5.4/mix#environment-variables) that should be available in my process.env variable but it’s not being injected, what am I missing here?

.env:

MIX_SOME_VAR=some_value

webpack.mix.js:

let mix = require('laravel-mix');
console.log(process.env); // a large object without my var
console.log(process.env.MIX_SOME_VAR); // undefined
...

I made sure to restart my npm run watch process after placing the variable

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:15

github_iconTop GitHub Comments

17reactions
rachid-essakhicommented, May 12, 2018

@diegocam the purpose of .env is to make your credentials secret, if every variable is available that means your secrets are accessible to anyone, that’s why the MIX_ prefix. But we have this options

AWS_ACCESS_KEY=somekey

MIX_AWS_ACCESS_KEY="${AWS_ACCESS_KEY}"

Access secret should do not me shared with mix 😉

17reactions
JeffreyWaycommented, Aug 4, 2017

You can’t access those env vars from your webpack.mix.js file, but you can from your main script. So if you have:

mix.js('resources/assets/js/app.js', 'js');

And then app.js has:

console.log(process.env.MIX_SOME_VAR);

Once you compile down, it’ll be:

console.log("some_value");
Read more comments on GitHub >

github_iconTop Results From Across the Web

MIX_ prefixed variable in .env not present in webpack.mix.js
Description: I place some variables inside my . env file prefixed with MIX_ as it is stated in documentation (https://laravel.com/docs/5.4/mix# ...
Read more >
How to pass env parameters to a Laravel Mix 6?
env variable with MIX_ , like MIX_FOO_VARIABLE=frontend . And then, in webpack.mix.js, you can do the following. console.log(process.env.
Read more >
Environment variables in Laravel Mix undefined
When I try to access environment variables in webpack.mix.js, they come back undefined. All I'm doing is defining MIX_VAR in .env, and in...
Read more >
How To Use .env Variables In Webpack.js
The solution to get these variables in your webpack.mix.js is to use a package called dotenv , which is already installed by Laravel...
Read more >
Compiling Assets (Mix) - Laravel - The PHP Framework For ...
Mix is a configuration layer on top of webpack, so to run your Mix tasks you only need to execute one of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found