Laravel-mix: Variable prefixed with MIX_ in .env file is not available for use

Created on 28 Aug 2017  路  2Comments  路  Source: JeffreyWay/laravel-mix

  • Laravel Mix Version: 1.4.2 (npm list --depth=0)
  • Node Version (node -v): 8.2.1
  • NPM Version (npm -v): 5.3.0
  • OS: Windows 10 x64
  • Laravel Version: 5.4.33

Description:

Variable prefixed with MIX_ in .env file is not available for use.

Steps To Reproduce:

Set up project and define host using WAMP. Define MIX_SENTRY_DSN_PUBLIC in .env.

When using mix.browserSync(process.env.MIX_SENTRY_DSN_PUBLIC) it will not work.
When I use console.log(process.env.MIX_SENTRY_DSN_PUBLIC) it shows undefined in console.
If I use mix.browserSync('http://example.com') then it works.

Note: I'm opening this again, since this behavior is NOT as expected. Laravel documentation clearly states that this should be working: https://laravel.com/docs/5.4/mix#environment-variables

I must repeat, this was working in earlier version. And how should different developers work in same project when everyone uses different url for browserSync?

All 2 comments

We have to compile your code down to parse your .env variables. So they aren't accessible from your webpack.mix.js file. Only your core JS bundle.

Hey Jeffrey - is there any alternative way to allow multiple URLs for browserSync? We've got multiple devs using different local development URLs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rderimay picture rderimay  路  3Comments

Cheddam picture Cheddam  路  3Comments

Bomavi picture Bomavi  路  3Comments

RomainGoncalves picture RomainGoncalves  路  3Comments

stefensuhat picture stefensuhat  路  3Comments