Skip to content

Email Template loading fails on cloudflare #199

@Vash1

Description

@Vash1

Problem

https://[domain].pages.dev/account/api?/updateProfile
fails during loading of the assets with the error:

"message": [
        "No email body: requires plaintextBody or htmlBody. Template: ",
        "welcome_email"
      ],

LLM Response

It looks like the email is not bundled correctly and this is apparently they are not included in the worker bundle:
You’re using this pattern:

const htmlTemplate = await import(
  `./emails/${template_name}_html.hbs?raw`
).then((mod) => mod.default)

This works locally because Vite (or your local bundler) understands ?raw and includes those files. But Cloudflare Pages Functions use their own esbuild-based runtime, and:
❗️**?raw imports are not guaranteed to work on Cloudflare by default.**

What I have tried so far

I'm a bit skeptic how this can be true, asthe live demo also uses cloudflare (at least recommends to do so)
I have tried
assetsInclude: ['**/*.hbs'], // in vite.config.ts

I also tried to specifically import the files and pass them (but invoking the render function there will cause "EvalError: Code generation from strings disallowed for this context"

And I have also tried switching from handlebars to eta with no success.

Additional Information

  • I'm using adapter-cloudflare instead of adapter-auto

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions