jason
jason
CDCloudflare Developers
Created by Cyb3r-Jak3 on 9/10/2024 in #pages-discussions
What wrangler version are you on?
This is now fixed, and the versions shown here now deploy successfully https://discord.com/channels/595317990191398933/1282858613097889864/1283135807481184326
18 replies
CDCloudflare Developers
Created by Paul on 9/14/2024 in #pages-discussions
waitUntil
Cloudflare has a special method called waitUntil (iirc) where you can put an asynchronous function and then return a response to the user. The response will be immediate but the function will stay active until your waitUntil item is done.
3 replies
CDCloudflare Developers
Created by Cyb3r-Jak3 on 9/10/2024 in #pages-discussions
What wrangler version are you on?
No description
18 replies
CDCloudflare Developers
Created by Cyb3r-Jak3 on 9/10/2024 in #pages-discussions
What wrangler version are you on?
Installing the latest wrangler as a project dependency did not resolve this error. This project is using nodejs_compat (not v2), which is why the error seems to be a bug in cloudflare. Guess I'll wait it out to see if/when others encounter it this too.
18 replies
CDCloudflare Developers
Created by Cyb3r-Jak3 on 9/10/2024 in #pages-discussions
What wrangler version are you on?
"peerDependencies": { "@sveltejs/kit": "^2.0.0", "wrangler": "^3.28.4" },
Looks like 3.28.4
18 replies
CDCloudflare Developers
Created by Cyb3r-Jak3 on 9/10/2024 in #pages-discussions
What wrangler version are you on?
I didn't realize Pages used wrangler from my project to deploy? Curious why that is. If it occurs with a less recent version of wrangler, then that's the cause because the SvelteKit cloudflare adapter uses an older version of wrangler
18 replies
CDCloudflare Developers
Created by jason on 8/2/2024 in #kv
I'm using Cloudflare Pages with KV.
Update for future searchers: the above env setup will eventually encounter a couple small edge cases. Use the following instead:
[[kv_namespaces]]
binding = "KV"
id = "<id>"
preview_id = "<id2>"

[[r2_buckets]]
binding = "R2"
bucket_name = "mysite-prod"
preview_bucket_name = "mysite-preview"

[[d1_databases]]
binding = "D1"
database_name = "mysite-prod"
database_id = "<uuid>"
preview_database_id = "<uuid2>"
migrations_dir = "./src/lib/server/database/migrations"
[[kv_namespaces]]
binding = "KV"
id = "<id>"
preview_id = "<id2>"

[[r2_buckets]]
binding = "R2"
bucket_name = "mysite-prod"
preview_bucket_name = "mysite-preview"

[[d1_databases]]
binding = "D1"
database_name = "mysite-prod"
database_id = "<uuid>"
preview_database_id = "<uuid2>"
migrations_dir = "./src/lib/server/database/migrations"
And target local/preview/production with these flags:
"list": "wrangler d1 migrations list D1 --local",
"list:preview": "wrangler d1 migrations list D1 --remote --preview",
"list:production": "wrangler d1 migrations list D1 --remote",
"list": "wrangler d1 migrations list D1 --local",
"list:preview": "wrangler d1 migrations list D1 --remote --preview",
"list:production": "wrangler d1 migrations list D1 --remote",
14 replies
CDCloudflare Developers
Created by jason on 8/9/2024 in #pages-help
`Error: Dynamic require of node:path is not supported` causes runtime error - how to troubleshoot?
For my case, using wrangler dev exposed the full error message which let me identify it was the mime-types package that uses node's path package (https://github.com/jshttp/mime-types/issues/82), and switching to the NPM mime package solves it--I just wrote my own minimal, mime validation function instead. I'd be dubious about SSR causing it b/c 1.) I used SSR on CF Pages previously successfully, and 2.) it's a key feature to support for each SvelteKit adapter (would be a big bug).
@Ben Does your stack trace from wrangler dev show the parent file that invokes the path module?
8 replies
CDCloudflare Developers
Created by ickerio on 7/18/2024 in #pages-help
pages_build_output_dir ignored in monorepo
Interesting. I didn’t need to do that, but might have it set up slightly differently. I have noticed that I get “unexpected pages_build_output_dir…” (iirc) or “missing pages_build_output_dir…” warnings about wrangler.toml and find myself commenting or uncommenting that line at various times to make it work for various commands. Which is also 🤷🏼‍♂️haha
13 replies
CDCloudflare Developers
Created by jason on 8/9/2024 in #pages-help
`Error: Dynamic require of node:path is not supported` causes runtime error - how to troubleshoot?
For SvelteKit, I have two terminals 1) npx wrangler dev (and all flags I need for D1, R2, etc). 2.) bun run build. Then I have to run “bun run build” after making any file changes and saving, bc it had to rebuild the HTML files that wrangler is watching. I don’t know about React-related aspects
8 replies
CDCloudflare Developers
Created by jason on 8/2/2024 in #kv
I'm using Cloudflare Pages with KV.
TDLR on feedback: - wrangler pages dev should print a message when no bindings are active too, so it's clear to new devs when things are not yet set up properly but they're unaware. - In wrangler.toml, consider more consistent naming of id and name, within each resource, because they're already scoped within kb_namespaces, r2_buckets, & d1_databases. The current mixed property naming convention (below) means devs needs to check the docs to see what each expects because it's not as consistent/predictable as it could be. - KV id - D1 database_id, database_name - R2 bucket_name Thanks for the help earlier!
14 replies
CDCloudflare Developers
Created by meowzillia on 8/12/2024 in #r2
Then no. Caching isn't available on the
Wait, S3 signed URLs to view an object from R2 can't be cached by Cloudflare CDN? Thought you could set a responseCacheControl header for the GetObjectCommand() command (I'm new to R2, so you might be right.)
3 replies
CDCloudflare Developers
Created by jason on 8/2/2024 in #kv
I'm using Cloudflare Pages with KV.
Posting in case it helps other searchers: Summary of environments for Cloudflare Pages, as I've learned: In wrangler.toml: 1. [env.production] specifies bindings for production. 2. Other bindings not within [env.production] are for preview environment (i.e. non-production branch, preview URLs). These resources are also used if wrangler dev --remote flag is specified. But wrangler pages dev --remote does NOT work for remote resources for Pages projects for D1 as noted in docs (not sure about KV and R1 yet), and this is fine b/c I don't need or want remote access when a project is run locally. 3. I removed preview_database_id for D1, preview_id for KV, and preview_bucket_name for R2 b/c Pages cannot access a remote D1 database anyway as noted in docs. 5. Locally, run wrangler pages dev --d1 D1 --kv KV --r2 R2 --live-reload to bind local resources for KV, R2, and D1. Wrangler will create these after this command is run the first time and their data will be persisted in .wrangler/state/v3 between runs. (TBD on how to clear our these resources and seed them consistently each time, but I'll figure that out.)
kv_namespaces = [
{ binding = "KV", id = "<id>" }
]
r2_buckets = [
{ binding = "R2", bucket_name = "mysite-preview" }
]
d1_databases = [
{ binding = "D1", database_name = "mysite-preview", database_id = "<id>" }
]

[env.production]
kv_namespaces = [
{ binding = "KV", id = "<id>" }
]
r2_buckets = [
{ binding = "R2", bucket_name = "mysite-prod" }
]
d1_databases = [
{ binding = "D1", database_name = "mysite-prod", database_id = "<id>" }
]
kv_namespaces = [
{ binding = "KV", id = "<id>" }
]
r2_buckets = [
{ binding = "R2", bucket_name = "mysite-preview" }
]
d1_databases = [
{ binding = "D1", database_name = "mysite-preview", database_id = "<id>" }
]

[env.production]
kv_namespaces = [
{ binding = "KV", id = "<id>" }
]
r2_buckets = [
{ binding = "R2", bucket_name = "mysite-prod" }
]
d1_databases = [
{ binding = "D1", database_name = "mysite-prod", database_id = "<id>" }
]
I'd prefer if wrangler set up local bindings automatically based on those inn wrangler.toml instead of needing to pass them as options to wrangler pages dev --d1 D1 --r2 R2 --kv KV. But super happy to have figured this out! Thanks so much
14 replies
CDCloudflare Developers
Created by jason on 8/2/2024 in #kv
I'm using Cloudflare Pages with KV.
I take it back--the CLI does output which bindings are active, in much the same way I suggested! lol (Although it doesn't show anything to indicate when no bindings are active, which would help.) It was just that none of my bindings were active until I passed bunx wrangler pages dev --d1 <binding> and saw this output for the first time. Thought the bindings would be picked up from my wrangler.toml like they are for other environments.
14 replies
CDCloudflare Developers
Created by jason on 8/2/2024 in #kv
I'm using Cloudflare Pages with KV.
Another piece of DX feedback: Sticking with just name and id for all of these in wrangler.toml would be more consistent; otherwise I found myself needing to look up what the expected key name is, which isn't needed given each is already scoped by kv_namespaces, r2_buckets, d1_databases, etc.
kv_namespaces = [
{ binding = "KV", id = "abc123" }
]
r2_buckets = [
{ binding = "R2", bucket_name = "mysite-prod" }
]
d1_databases = [
{ binding = "D1", database_name = "mysite-prod", database_id = "xyz456" }
kv_namespaces = [
{ binding = "KV", id = "abc123" }
]
r2_buckets = [
{ binding = "R2", bucket_name = "mysite-prod" }
]
d1_databases = [
{ binding = "D1", database_name = "mysite-prod", database_id = "xyz456" }
14 replies
CDCloudflare Developers
Created by jason on 8/2/2024 in #kv
I'm using Cloudflare Pages with KV.
Thanks again @thomasgauvin Helpful! Idea: When running the wrangler pages dev command, it'd be informative--and reassuring--if it printed out what resource bindings are active. For example: wrangler pages dev Active bindings: - D1: FOO (local) - KV: BAR (local) - R2: BAZ (local) wrangler pages dev --remote Active bindings: - D1: FOO (remote: <foo-name>, <id>) - KV: BAR (remote: <bar-name>, <id>) - R2: BAZ (remote: <baz-name>, <id>) or No bindings. Add to wrangler.toml. Example: <linkShowingEveryResourceSetUpForRemoteAccess> (Duplicate a bulleted line if there are multiple bindings for a given resource type.)
14 replies