Fix build of workers#9
Merged
Merged
Conversation
Cloudflare Pages is deprecated in favour of Workers. This migrates the project to use `wrangler deploy` (Workers) instead of `wrangler pages deploy`. - Replace wrangler.toml with wrangler.jsonc, adding `main` and `assets` config for Workers instead of `pages_build_output_dir` - Remove `functions/[[path]].ts` Pages function handler (no longer needed) - Remove `@remix-run/cloudflare-pages` and `@remix-run/css-bundle` dependencies - Update deploy/start scripts to use `wrangler deploy` / `wrangler dev` - Update GitHub Actions workflows to deploy via Workers - Bump compatibility_date to 2024-11-18 - Bump wrangler, @cloudflare/workers-types, @remix-run/*, vite, typescript - Fix trailing quote typo in reset-preview-d1 workflow https://claude.ai/code/session_018HoDZ4bsqTYLdXLgfZvE7a
The Remix Vite build outputs server modules at build/server/index.js but doesn't export a default fetch handler. Add worker.ts as the Worker entry point that wraps the Remix request handler, and point wrangler.jsonc main to it so Wrangler bundles it correctly. https://claude.ai/code/session_018HoDZ4bsqTYLdXLgfZvE7a
Use the Remix Vite plugin's `server` option to compile worker.ts as part
of the Remix build. This produces build/server/index.js with a proper
`export default { fetch }` that wrangler detects as ES module format,
fixing the D1 binding error that requires ES module workers.
https://claude.ai/code/session_018HoDZ4bsqTYLdXLgfZvE7a
Signed-off-by: James Bithell <Jbithell@users.noreply.github.com>
Wrangler's bundler was producing service-worker format output despite the worker entry having `export default`. Fix by pre-bundling worker.ts with esbuild (--format=esm) as a post-build step, then using `no_bundle: true` in wrangler.jsonc so wrangler deploys the pre-built ESM file as-is. Also removes the invalid `server` option from the Remix Vite plugin config (that option is for the classic Remix compiler, not the Vite plugin) and adds esbuild as an explicit devDependency. https://claude.ai/code/session_018HoDZ4bsqTYLdXLgfZvE7a
The --platform=neutral flag ignores `main` fields in package.json, causing unresolved module errors for dependencies imported by the Remix server build. Switch to --platform=browser which respects main/module fields. https://claude.ai/code/session_018HoDZ4bsqTYLdXLgfZvE7a
|
Built preview on Cloudflare Workers: Logs. Run Migrations or Reset Preview DB |
|
Built preview on Cloudflare Workers: Logs. Run Migrations or Reset Preview DB |
@remix-run/dev@2.x has peerOptional wrangler@^3, which conflicts with wrangler@4. This is safe since the peer dep is optional. https://claude.ai/code/session_018HoDZ4bsqTYLdXLgfZvE7a
remix-validated-form declares @remix-run/server-runtime as a peer dep. With legacy-peer-deps=true, peer deps aren't auto-installed, so the esbuild worker bundling step can't resolve it. Adding it explicitly ensures it's always available. https://claude.ai/code/session_018HoDZ4bsqTYLdXLgfZvE7a
|
Built preview on Cloudflare Workers: Logs. Run Migrations or Reset Preview DB |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request migrates the project from Cloudflare Pages to Cloudflare Workers, updating deployment workflows, configuration files, and dependencies to match the new platform. It also removes legacy code and updates scripts and settings for improved compatibility and performance.
Cloudflare Workers migration:
cloudflare-pages-deploy.yml,cloudflare-pages-preview.yml,migrate-preview-d1.yml,reset-preview-d1.yml) to deploy to Cloudflare Workers instead of Pages, including changes to deployment commands, Node version, and removal ofwranglerVersionspecification. [1] [2] [3] [4]functions/[[path]].tsand replaced it with a new Worker entrypointworker.tsusing@remix-run/cloudflare. (functions/[[path]].tsL1-L8, worker.tsR1-R23)Configuration updates:
wrangler.tomlwith a newwrangler.jsoncconfiguration file, updating references throughout the codebase and ensuring proper D1 database bindings for production and preview environments. [1] [2] [3]vite.config.tsto use the new Worker entrypoint and reference the correct configuration file.load-context.tscomments to reflect the new configuration file and clarify type generation.Dependency and script updates:
package.jsonto latest versions, including@remix-run/cloudflare,miniflare,wrangler, and others for compatibility with Workers. [1] [2] [3]