Missing templates on staging and production

I have a feature that allows users to generate PDFs. This is done by creating an HTML version of the page and using Puppeteer to render it to a PDF. This feature worked fine but recently we made some changes to our Cloudformation templates, and had to spin up new EC2 instances. This broke puppeteer. I’ve reinstalled it and updated the Node version. Now, however I’m not even getting to the PDF generate, the application is throwing this error message:

(Phoenix.Template.UndefinedError) Could not render "quote_pdf.html" for StorefrontWeb.PDFView, please define a matching clause for render/2 or define a template at "lib/storefront_web/templates/pdf/**/*". No templates were compiled for this module.

But quote_pdf.html does exist, it hasn’t moved or changed, and I’ve redeployed a few times just to be sure. I’ve even changed up the file suffix from, trying .html.eex .html.leex, .html.heex. I’ve also created other dummy HTML files in that directory to be sure.

#uses view to call `render/2`
 use StorefrontWeb, :view

  @spec to_pdf(Map.t()) :: {:ok, String.t()} | {:error, atom()}
  def to_pdf( assigns) do

    filename = create_filename(assigns)
    render_pdf("quote_pdf.html", filename, assigns)
  end

  # sobelow_skip ["Traversal.FileModule"]
  defp render_pdf(template, filename, %{quote_id: quote_id} = assigns) do
    root_path = Application.get_env(:storefront_web, :tmp_dir)

    with html <- render_html(template, assigns),
        # the next clauses are never called 
         html_path <- Path.join([root_path, "#{filename}.html"]),
         pdf_path <- Path.join([root_path, "#{filename}.pdf"]),
         :ok <- File.write(html_path, html),
         {_, 0} <-
           System.cmd("puppeteer-pdf", [
             html_path,
             "--path",
             pdf_path
           ]) do
     ... 
  end

  def render_html(template, assigns) do
    template
    |> __MODULE__.render(assigns)
    |> html_escape()
    |> safe_to_string()
  end

Any idea why my template is no longer being found? I mentioned the server and node updates because they happened at the same time this stopped working however all the related errors went away when I got Puppeteer installed so I don’t think they are related.

Can you provide where is your view, template modules placed, theirs name. And how you call render/3 from your controller ? And also what is controller name. If you haven’t touched modules (like renaming or moving) thats strange. Also what are your phoenix, view versions ?

the view: app/apps/storefront_web/lib/storefront_web/views/pdf_view.ex
the template: app/apps/storefront_web/lib/storefront_web/templates/pdf/quote_pdf.html.eex

The view method, to_pdf/1 is not called by a controller, but a worker.

I didn’t make this clear above but this all works locally (all my tests have also worked locally as well).

I’d be curious if there was a way to view all the templates compiled for a module, I looked into how Phoenix does this a bit on Friday but was unable to find an easy way of doing it.

Is the _build directory carried over between deploys on the server? If so maybe try clearing it out to force a full recompile.

Thanks for the advice, I’m beginning to think the whole missing template thing was a red herring. After rolling back the above mentioned changes I’m still getting errors from Puppeteer that it can’t find Chromium. I think that is the root of the issue rather than missing templates.

1 Like