Issue with @clerk/astro and node:async_hooks on Cloudflare Pages - Local works

For Workers & Pages, what is the name of the domain?

my-alumni-site.pages.dev

What is the error message?

[ERROR] Error: No such module “node:async_hooks”. at createAsyncLocalStorage (_astro-internal_middleware.mjs:5 305:33) at _astro-internal_middleware.mjs:5 308:30

What is the issue or error you’re encountering

I’m encountering a persistent issue while trying to integrate @clerk/astro (an authentication library for Astro) with my website hosted on Cloudflare Pages. Interestingly, the application works perfectly fine in my local development environment, and the deployment to Cloudflare Pages also succeeds without any build errors. However, when I try to access the deployed site, I consistently receive an Internal Server Error 5 00. Upon checking the Cloudflare Functions Log Streaming, I’ve confirmed the following error is occurring: [ERROR] Error: No such module “node:async_hooks”. at createAsyncLocalStorage (_astro-internal_middleware.mjs:5 305:33) at _astro-internal_middleware.mjs:5 308:30 This error strongly suggests that the node:async_hooks module, which is part of Node.js, is not available or not fully supported in the Cloudflare Pages environment, specifically within the Cloudflare Functions that power the server-side rendering.

What steps have you taken to resolve the issue?

Here are the steps I’ve already taken:

Reviewed the @clerk/astro documentation for Cloudflare Pages specific instructions (found none).
Added node:async_hooks to the vite.ssr.external array in my astro.config.mjs.
Created a wrangler.toml file and tried using compatibility_flags = [“nodejs_compat”] and compatibility_flags = [“nodejs_als”], but the error persists on accessing the deployed site.
My astro.config.mjs looks like this:

JavaScript

import { defineConfig } from “astro/config”;
import cloudflare from ‘@astrojs/cloudflare’;

export default defineConfig({
adapter: cloudflare({}),
output: ‘server’,
vite: {
ssr: {
external: [‘node:buffer’, ‘node:async_hooks’],
},
},
});
And my wrangler.toml (tried both):

Ini, TOML

name = “your-project-name”
compatibility_date = “2023-03-24” # Tried with a recent date as well
compatibility_flags = [“nodejs_compat”]
Ini, TOML

name = “your-project-name”
compatibility_date = “2023-03-24” # Tried with a recent date as well
compatibility_flags = [“nodejs_als”]
The fact that it works locally but fails with this specific node:async_hooks error on Cloudflare Pages access makes me believe there’s a fundamental incompatibility or a missing configuration step for this particular module in the Cloudflare environment.

Has anyone else encountered this issue with @clerk/astro (or other libraries using node:async_hooks) on Cloudflare Pages? Are there any known workarounds or specific configurations required to resolve this?

Any insights or suggestions would be greatly appreciated.

Thank you.

I couldn’t resolve the issue on Cloudflare Pages, so I tried deploying to Netlify instead, and everything worked fine there without any problems. Although the root cause remains unresolved, I’d like to consider this matter closed for now. Thank you.

This topic was automatically closed after 15 days. New replies are no longer allowed.