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:
- Created 6 years ago
- Reactions:2
- Comments:15
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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
Access secret should do not me shared with mix 😉
You can’t access those env vars from your webpack.mix.js file, but you can from your main script. So if you have:
And then app.js has:
Once you compile down, it’ll be: