stibbs
stibbs
CDCloudflare Developers
Created by stibbs on 11/7/2024 in #pages-help
How to use --persist-to flag when starting local FE with e.g., vite dev?
I have a monorepo where a number of packages share the same D1, KV, etc. For local DX it would be great to be able to create one local version and reuse it across all packages. This is achievable when starting local Workers etc by appending the --persist-to ../path/here flag to wrangler dev. Is there an equivalent way to point my frontend to the persisted resource? I.e., start the SvelteKit dev server (via vite dev) and have it use the persisted resource instead of create another .wrangler/ directory in the FE directory
3 replies
CDCloudflare Developers
Created by stibbs on 5/10/2024 in #workers-help
How to rapidly validate if a JS package will work on Workers runtime?
Like the old 'Works on Workers' catalogue which disappeared. Node.js / javascript / typescript packages. I know this page exists: https://developers.cloudflare.com/workers/runtime-apis/nodejs/ but without a deep dive into other packages you cannot identify whether a package will 'just work'. As an example of two popular packages, stripe works but @sendgrid/mail doesn't Is it a matter of trial and error? Or Google [package] cloudflare workers each time and hope someone has written a blog post? That will become exhausting quickly. Or assume nothing works and default to building from scratch (or more likely, electing to run my FaaS elsewhere.. 😢 ) This sounded really whingy and I don't intend it to be. I really love the product, it is just not the easiest to use right now!
5 replies
CDCloudflare Developers
Created by stibbs on 5/6/2024 in #pages-help
Are environment variables available at build or only runtime?
My SvelteKit builds fail when I use import { SECRET } from '$env/static/private' or the public equivalent ($env/static/public) with an error such as:
RollupError: "SECRET" is not exported by "virtual:$env/static/private"
RollupError: "SECRET" is not exported by "virtual:$env/static/private"
However accessing environment variables via import { env } from '$env/dynamic/private'; works. Is it correct to assume environment variables created on Cloudflare Pages are only available at runtime?
52 replies
CDCloudflare Developers
Created by stibbs on 5/2/2024 in #pages-help
Is it possible to make the build system ignore asdf .tool-versions?
Is it possible to make the build system ignore .tool-versions? There are prior threads on here + on community.cloudflare.com (e.g., https://community.cloudflare.com/t/how-to-disable-automatic-installs-of-tool-versions-and-package-json/570450) I've set the NODE_VERSION = 22.0.0 environment variable in the build settings. Failed build log:
Found a .tool-versions file in user-specified root directory. Installing dependencies.
pnpm plugin is not installed
Error: Exit with error code: 1
at ChildProcess.<anonymous> (/snapshot/dist/run-build.js)
at Object.onceWrapper (node:events:652:26)
at ChildProcess.emit (node:events:537:28)
at ChildProcess._handle.onexit (node:internal/child_process:291:12)
Failed: build command exited with code: 1
Failed: error occurred while running build command
Found a .tool-versions file in user-specified root directory. Installing dependencies.
pnpm plugin is not installed
Error: Exit with error code: 1
at ChildProcess.<anonymous> (/snapshot/dist/run-build.js)
at Object.onceWrapper (node:events:652:26)
at ChildProcess.emit (node:events:537:28)
at ChildProcess._handle.onexit (node:internal/child_process:291:12)
Failed: build command exited with code: 1
Failed: error occurred while running build command
1 replies
CDCloudflare Developers
Created by stibbs on 5/1/2024 in #pages-help
How do I work with local D1 in a SvelteKit project?
I've created a new SvelteKit project and can successfully interact with hosted D1 after following the guide https://developers.cloudflare.com/d1/examples/d1-and-sveltekit/. Using pnpm dev to launch the SvelteKit local dev environment as standard works for the hosted D1. However I would like to develop locally also. The guide advises to pass --d1 BINDING_NAME=DATABASE_ID to wrangler dev (e.g., npx wrangler dev --d1 DB=example-uuid-here) but this results in ✘ [ERROR] Unknown argument: d1 (which aligns with wrangler's docs https://developers.cloudflare.com/workers/wrangler/commands/#dev, no d1 option exists) I have the following config:
# wrangler.toml
name = "example"
compatibility_date = "2024-04-23"

[[d1_databases]]
binding = "DB"
database_name = "example-prod"
database_id = "example-uuid-here"
# wrangler.toml
name = "example"
compatibility_date = "2024-04-23"

[[d1_databases]]
binding = "DB"
database_name = "example-prod"
database_id = "example-uuid-here"
If I run npx wrangler dev I receive: ✘ [ERROR] Missing entry-point: The entry-point should be specified via the command line (e.g. wrangler dev path/to/script) or the main config field.
8 replies