[1.4.6] Deployments to Cloudflare break after upgrading from v1.4.5 to v1.4.6

✘ [ERROR] A request to the Cloudflare API (/accounts/<account_id>/workers/scripts/suite-control-dev/versions) failed.

  Uncaught TypeError: The argument 'path' The argument must be a file URL object, a file URL
  string, or an absolute path string.. Received 'undefined'
    at null.<anonymous> (node:module:34:15) in createRequire
    at null.<anonymous>
  (file:///Users/jakst/code/endform/node_modules/.pnpm/better-auth@1.4.6_solid-js@1.9.10/node_modules/better-auth/dist/chunk-DieNfLhd.mjs:50:33)
   [code: 10021]
  To learn more about this error, visit:
  https://developers.cloudflare.com/workers/observability/errors/#validation-errors-10021


I asked Opus 4.5 to create a patch, and this is the summary:


Root Cause

In better-auth v1.4.6, the bundler (rolldown) generates a helper chunk (chunk-DieNfLhd.mjs) that contains:

import { createRequire } from "node:module";
var __require = /* @__PURE__ */ createRequire(import.meta.url);


This chunk is now imported by get-migration-CDvYpogu.mjs (which wasn't the case in v1.4.5) to get __export and __reExport helpers.

The problem is that in Cloudflare Workers, import.meta.url is undefined, causing createRequire(undefined) to throw:
TypeError: The argument 'path' must be a file URL object, a file URL string, or an absolute path string. Received 'undefined'

The Fix

Created a patch file patches/better-auth@1.4.6.patch that:

  1. Adds a fallback for import.meta.url: var __import_meta_url = typeof import.meta.url === 'string' ? import.meta.url : 'file:///';
  2. Uses this safe fallback instead of raw import.meta.url: var __require = createRequire(__import_meta_url);
This allows the code to run in Cloudflare Workers where import.meta.url is undefined, while still working correctly in Node.js environments.
Was this page helpful?