Pow in phoenix 1.7.2 api

Hello everyone!
I am fairly new to phoenix, and i was trying to make an api with it (was it a mistake¿?) and after a quick research use pow library for the authentication.
Problem: after creating the phoenix api with

mix phx.new my_api --no-live --no-assets --no-html --no-dashboard --no-mailer --binary-id --no-tailwind --no-esbuild

add to the mix.exs

  defp deps do
    [
      {:phoenix, "~> 1.7.2"},
      #....
      {:pow, "~> 1.0.29"}
    ]
  end

execute mix deps.get
following the oficial guide (GitHub - pow-auth/pow at v1.0.29), after executing

mix pow.ecto.install
# or
mix pow.install

I get the next error:

== Compilation error in file lib/pow/phoenix/html/core_components.ex ==
** (CompileError) lib/pow/phoenix/html/core_components.ex:5: module Phoenix.Component is not loaded and could not be found. This may be happening because the module you are trying to load directly or indirectly depends on the current module
    (elixir 1.14.3) expanding macro: Kernel.use/1
    lib/pow/phoenix/html/core_components.ex:5: Pow.Phoenix.HTML.CoreComponents (module)
could not compile dependency :pow, "mix compile" failed. Errors may have been logged above. You can recompile this dependency with "mix deps.compile pow", update it with "mix deps.update pow" or clean it with "mix deps.clean pow"

did i miss any flag in the creation of the api? pow in the release notes it says that is compatible with phoenix 1.7, but maybe is only compatible with a ssr phoenix app?

Do you guys have a recommendation for api authorisation?

Thanks so much in advance, and sorry if this is asked a lot or it is really trivial

I think the problem could be that you passed --no-html flag when creating the Phoenix project, but Pow depends on it (Pow imports Phoenix.Component).

BTW these flags not always mean what you think they are (at least that’s the case for myself). The other day I created a new Phx project without LV functionality (--no-live flag), but it still adds phoenix_live_view to Mix as the project then depends on phoenix_live_view for Heex templates rendering. These flags vary in “integration” levels when not used, for example the mentioned --no-live flag will not inject any LV related config into endpoint/router/etc files but still depends to some degree on the actual LV library (like the heex templates).

You are right, if i make the test creating the api without the flag ---no-html, and then delete the extra files everything works smoothly. Clearly i have to dig more in those phoenix tasks… Thanks for your answer!

the --no-live flag is deprecated as of 1.7.x

I found out the same way you did. But then ran across in the release notes that now phoenix just comes with liveview by default in the deps (so it’s a required dep, but doesn’t produce anything in the project unless you use the dependency).

Can you link to the release notes stating --no-live is deprecated ? I cannot find it.

The phx.new still lists --no-live as option in its docs mix phx.new — Phoenix v1.7.2

Perhaps it shall be renamed --no-socket

1 Like

I cannot find what I was referring to. Let’s see if anyone answers here Is the mix phx.gen [...] --no-live flag deprecated in 1.7? · Issue #5390 · phoenixframework/phoenix · GitHub

I am also interested, because on the official documentation (JSON and APIs — Phoenix v1.7.2), the --no-live flag for creating a new api is not mentioned

It’s still part of the mix task phoenix/phx.new.ex at main · phoenixframework/phoenix · GitHub

I actually wasn’t saying that it reads it’s deprecated in the release notes fwiw. I was asserting it is was deprecated (and I was wrong) because I read in the release notes that liveview just comes with phoenix by default now :slight_smile: