#`configure` causing build error in Cloudflare
1 messages · Page 1 of 1 (latest)
Are you sure node compat mode is on properly? It's been a while since I've used Cloudflare but I thought that warning disappeared if compat mode was on
Yep, I have this rn
node_compat = true
name = "api"
compatibility_date = "2024-07-12"
vars = { ENVIRONMENT = "development", TRIGGER_API_KEY = "", DATABASE_URL = "" }
Removing node_compat throws a bunch of some other errors
Maybe cloudflare just doesn't have a polyfill for "node:async_hooks
They definitely do: https://developers.cloudflare.com/workers/runtime-apis/nodejs/asynclocalstorage/
Hmm interesting… they have this:
compatibility_flags = [ "nodejs_als" ]
That just enables the async hooks
Are you on a newish version of wrangler? What's your compatibility date?
I assume you can add that compat flag as well as the node one
compatibility_date = "2024-07-12"
I just added the flag
It still show's a warning but I expect it to work now.
☝️ Ha that's exactly how I found out about this
Thank you for all the help!
No problem, I'm making notes of all these problems you hit because we need to create docs for so many of these things. Like a guide for Cloudflare
Awesome!
I wonder how the configure works, If I can just call it in a middleware, and expect any trigger call to work
Like instead of this:
const triggerMiddleware = createMiddleware<HonoOptions>(async (ctx, next) => {
ctx.set('configureTriggerClient', () => {
configureTriggerClient({
secretKey: ctx.env.TRIGGER_API_KEY,
});
});
await next();
});
I can do:
const triggerMiddleware = createMiddleware<HonoOptions>(async (ctx, next) => {
configureTriggerClient({
secretKey: ctx.env.TRIGGER_API_KEY,
});
await next();
});
Actually only one way to find out.. 😁
As long as that's called before any of the SDK calls then you'll be fine
That's sweet
@fleet tangle
You're most likely already aware of this. In Cloudflare, this method documented here works better https://trigger.dev/docs/v3/triggering#tasks-trigger:
import { tasks } from "@trigger.dev/sdk/v3";
import type { emailSequence } from "~/trigger/emails";
await tasks.trigger<typeof emailSequence>("email-sequence", {
to: data.email,
name: data.name,
});
As the regular emailSequence.trigger({}) throws error of one of the tasks uses process.env and checks if the env is available, cloudflare throws process.env not found etc.
Yes we should make that clearer in the docs. It’s the same for Supabase edge functions and Deno too
That's actually a bug, all env var access through should work cross platform, but one might have slipped through
@charred heath can you send me the stacktrace?
Sure! gimme a sec
I think wrangler swallows most of the error, it just shows this.
createDb is used in the trigger package like this: const db = createDb(process.env.DB_URL);
And the content of createDb:
export const createDb = (databaseUrl?: string) => {
if (!databaseUrl) {
throw new Error('DB_URL is required');
}
const client = postgres(databaseUrl, { prepare: false });
return drizzle(client, { schema })
};
I'm not sure if there is a way to enable debug mode for cloudflare wrangler
wrangler dev --log-level debug works
--- 2024-07-20T22:28:41.423Z debug
Failed to load .env file ".env": Error: ENOENT: no such file or directory, open '.env'
at Object.openSync (node:fs:581:18)
at Object.readFileSync (node:fs:457:35)
at tryLoadDotEnv (/Users/yinks/Projects/innkeeper/node_modules/wrangler/wrangler-dist/cli.js:159217:72)
at loadDotEnv (/Users/yinks/Projects/innkeeper/node_modules/wrangler/wrangler-dist/cli.js:159226:12)
at /Users/yinks/Projects/innkeeper/node_modules/wrangler/wrangler-dist/cli.js:202152:20
at /Users/yinks/Projects/innkeeper/node_modules/wrangler/wrangler-dist/cli.js:165885:16
at maybeAsyncResult (/Users/yinks/Projects/innkeeper/node_modules/wrangler/wrangler-dist/cli.js:164106:44)
at /Users/yinks/Projects/innkeeper/node_modules/wrangler/wrangler-dist/cli.js:165884:14
at /Users/yinks/Projects/innkeeper/node_modules/wrangler/wrangler-dist/cli.js:164093:22
at Array.reduce (<anonymous>) {
errno: -2,
code: 'ENOENT',
syscall: 'open',
path: '.env'
}
---