Could not start application returned a bad value: {Phoenix.PubSub, [name: AppName.PubSub, adapter: Phoenix.PubSub.PG2]}

Hi,
I am new to elixir while doing setup I am facing this issue. Can anyone help me?
I change the phoenix version from 1.4.6 to 1.5.9 and phoenix_pubsub version from 1.1 to 2.0

while starting the server I am getting

(Mix) Could not start application AppName: AppName.Application.start(:normal, []) returned a bad value: {Phoenix.PubSub, [name: AppName.PubSub, adapter: Phoenix.PubSub.PG2]}

Show us code of AppName.Application.start/2

1 Like
defmodule AppName.Application do
  # See https://hexdocs.pm/elixir/Application.html
  # for more information on OTP Applications
  @moduledoc false

  use Application

  def start(_type, _args) do
    # List all child processes to be supervised
    children = [
      # Start the Ecto repository
      AppName.Repo,
      # Start the endpoint when the application starts
      AppNameWeb.Endpoint
      # Starts a worker by calling: AppName.Worker.start_link(arg)
      # {AppName.Worker, arg},
    ]

    # See https://hexdocs.pm/elixir/Supervisor.html
    # for other strategies and supported options
    opts = [strategy: :one_for_one, name: AppName.Supervisor]
    Supervisor.start_link(children, opts)
    {Phoenix.PubSub, [name: AppName.PubSub, adapter: Phoenix.PubSub.PG2]}
  end

  # Tell Phoenix to update the endpoint configuration
  # whenever the application is updated.
  def config_change(changed, _new, removed) do
    AppNameWeb.Endpoint.config_change(changed, removed)
    :ok
  end
end

Are you asking for this code?

Try to remove this part…

Try to wrap your code with 3x ` and use Markdown format to make it readable. I made the change this time :slight_smile:

Maybe show your config/config.exs

UPDATE: After reformat, I can see You did not put the line at the right place. It should be in the children list.

2 Likes

config/config.exs

# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
#
# This configuration file is loaded before any dependency and
# is restricted to this project.

# General application configuration
use Mix.Config

config :app_name,
  ecto_repos: [AppName.Repo]

# Configures the endpoint
config :app_name, AppName.Endpoint,
  url: [host: "localhost"],
  secret_key_base: "hBX1LohmoZcLs9LErp8h1s7vasrURloJYqF4q+KtEQ3lYoLS1WEvPpYdFDvQGq6s",
  render_errors: [view: AppName.ErrorView, accepts: ~w(json)],
  pubsub_server: AppName.PubSub
# Configures Elixir's Logger
config :logger, :console,
  format: "$time $metadata[$level] $message\n",
  metadata: [:request_id]

# Use Jason for JSON parsing in Phoenix
config :phoenix, :json_library, Jason

# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{Mix.env()}.exs"

I tried by removing , adapter: Phoenix.PubSub.PG2. still facing same issue.

Yes, it should be:

defmodule AppName.Application do
  @moduledoc false

  use Application

  def start(_type, _args) do
    # List all child processes to be supervised
    children = [
      AppName.Repo,
      {Phoenix.PubSub, [name: AppName.PubSub, adapter: Phoenix.PubSub.PG2]},
      AppNameWeb.Endpoint
    ]

    opts = [strategy: :one_for_one, name: AppName.Supervisor]
    Supervisor.start_link(children, opts)
  end

  def config_change(changed, _new, removed) do
    AppNameWeb.Endpoint.config_change(changed, removed)
    :ok
  end
end
2 Likes

Thank you!. Its working now.