typescriptsendgridcloudflareastrojs

Astro site on Cloudflare Pages intermittent ReferenceError


I have a hybrid site built with Astro and deployed to Cloudflare pages. I have two API endpoints, one for a newsletter signup and one for a contact form - both interact with the SendGrid API. Both will work as intended sometimes, but often fail with the error "ReferenceError: reset is not defined" being logged in the Cloudflare functions real-time logs. Both need to read my SendGrid API key as an environment variable; I used Astro's astro:env API to do this.

Full exception text:

"exceptions": [
      {
        "stack": "    at chunks/server_ChVHT3Lq.mjs:27:2\n    at setGetEnv (chunks/astro/env-setup_E0oxRp6C.mjs:163:3)\n    at Object.fetch (chunks/_@astrojs-ssr-adapter_ho7DYPta.mjs:1077:5)",
        "name": "ReferenceError",
        "message": "reset is not defined",
        "timestamp": 1728762389258
      }
    ],

I can't tell if I'm doing something incorrectly with Astro, or if this is a Cloudflare issue.


Solution

  • This issue was caused by a bug introduced in version 4.16.2 of Astro.

    Full bug report and linked pull request with fix is available here: https://github.com/withastro/astro/issues/12210