Getting error GOOGLE-APPLICATION-CREDENTIALS not set when starting phoenix server

When I am starting phoenix server, I am getting following error

** (Mix) Could not start application hndl: exited in: Hndl.Application.start(:normal, [])
    ** (EXIT) an exception was raised:
        ** (RuntimeError) GOOGLE_APPLICATION_CREDENTIALS not set
            (hndl 0.2.10) lib/hndl/application.ex:49: Hndl.Application.validate_required_config/0
            (hndl 0.2.10) lib/hndl/application.ex:12: Hndl.Application.start/2
            (kernel 9.2.3) application_master.erl:293: :application_master.start_it_old/4

I am setting google credentials through following command

export GOOGLE_APPLICATION_CREDENTIALS="/Users/.../google-credentials.json"

and when I check through following command

echo $GOOGLE_APPLICATION_CREDENTIALS

It gives me right path.
But still I am getting error on starting server. What is causing the issue?

Hello and welcome,

I would look at the config files to check how this env variable is passed to the application.

You should provide more information if You expect better answers than a simple guess.

In particular the dependency that requires this param.

Also, are You starting the server in dev or prod mode?

I am starting the server in dev mode.
Actually its my first time using google application credentials so I don’t know much where to look.

But in my config files, I found following in runtime.exs file

config :hndl, GOOGLE_APPLICATION_CREDENTIALS: System.get_env("GOOGLE_APPLICATION_CREDENTIALS")
config :hndl, GOOGLE_CLOUD_STORAGE_BUCKET: System.get_env("GOOGLE_CLOUD_STORAGE_BUCKET")
config :hndl, GOOGLE_MAP_API_KEY: System.get_env("GOOGLE_MAP_API_KEY")

In config.exs I found this (don’t know if related)

config :hndl, google_map_geocoding_url: "https://maps.googleapis.com/maps/api/geocode/json"

config :hndl,
  registered_tenants: [
    "handel",
    "ipswich",
    "cogc",
    "events"
  ]

config :hndl,
  google_map_autocomplete_url: "https://maps.googleapis.com/maps/api/place/autocomplete/json"

config :hndl,
  google_places_from_text_url: "https://maps.googleapis.com/maps/api/place/findplacefromtext/json"

I can provide more information if required.
btw thanks for your response

It’s because the runtime config file is generally used for production only…

if config_env() == :prod do
 ...
end

You should copy the required config part to dev.exs… or move the config under the if condition

1 Like