process.env.MIX_ALGOLIA_APP_ID not recognized in laravel/vue app

Hi,

  searchClient: algoliasearch(process.env.MIX_ALGOLIA_APP_ID, process.env.MIX_ALGOLIA_SEARCH
                    // appId = process.env.MIX_ALGOLIA_APP_ID,
                    // apiKey = process.env.MIX_ALGOLIA_SEARCH
                ),

For the past few days I’ve been having a hard time.

I’ve installed Laravel Scout, instant search, via https://www.algolia.com/doc/framework-integration/laravel/tutorials/getting-started-with-laravel-scout-vuejs/?language=php

Also, I found https://laracasts.com/discuss/channels/javascript/mix-environmental-variables-not-working This solution was a bit hacky.

I know my issue is the env variables because when they are hardcoded (in dev) they work, hit the server, etc.

Thank you,
Trevor

Hi @BidBird,
Just to confirm, this problematic

  searchClient: algoliasearch(process.env.MIX_ALGOLIA_APP_ID, process.env.MIX_ALGOLIA_SEARCH
                    // appId = process.env.MIX_ALGOLIA_APP_ID,
                    // apiKey = process.env.MIX_ALGOLIA_SEARCH
                ),

is in your front-end code, correct? What error are you receiving here? And using the computed values as suggested in https://laracasts.com/discuss/channels/javascript/mix-environmental-variables-not-working works as expected?

Hi good morning ~

the searchClient is part of a vue component. I’m trying to follow the basic pattern shown on algolia’s site.

I gave the computed properties a go, from laracasts, but it did not seem to fix accessing the env variables.

When looking at how the script is called, I did change this in the master.blade file <script src="{{ mix('js/app.js') }}"></script> from asset to mix. Even still, only the hard coded version seems to work.

It’s puzzling, but Im sure some small thing. Working off this: https://laravel.com/docs/6.x/mix#environment-variables

I use npm run dev, and then npm run watch while working locally.

Thank you,

Trevor

alright, so basic…

php artisan config:clear

that command does it! Maybe add a reminder in docs?

Hi @BidBird, Thanks for letting us know how you solved this in your application!

I will pass this information on to our Documentation team!