From 2ec0de32644f5d0514ed511741055632525d0d2c Mon Sep 17 00:00:00 2001 From: Dorseuil Nicolas Date: Mon, 5 May 2025 19:13:49 +0200 Subject: [PATCH 1/3] polyfill import.meta.url --- packages/cloudflare/src/cli/templates/init.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/cloudflare/src/cli/templates/init.ts b/packages/cloudflare/src/cli/templates/init.ts index 9d627803..61a796fc 100644 --- a/packages/cloudflare/src/cli/templates/init.ts +++ b/packages/cloudflare/src/cli/templates/init.ts @@ -94,6 +94,11 @@ function initRuntime() { __BUILD_TIMESTAMP_MS__: __BUILD_TIMESTAMP_MS__, __NEXT_BASE_PATH__: __NEXT_BASE_PATH__, }); + + // Some packages rely on `import.meta.url` (i.e. payload) but it is undefined in workerd + // It cause a bunch of issue, and will make even import crash + // TODO: verify that it won't cause other issues later with other packages + import.meta.url = "file:///worker.js"; } /** From 5ad0aeed4d7fcfd5bdb91b8c3f9095a4c6dfcdf3 Mon Sep 17 00:00:00 2001 From: Dorseuil Nicolas Date: Tue, 6 May 2025 08:45:18 +0200 Subject: [PATCH 2/3] review fix --- packages/cloudflare/src/cli/templates/init.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/cloudflare/src/cli/templates/init.ts b/packages/cloudflare/src/cli/templates/init.ts index 61a796fc..98e476c6 100644 --- a/packages/cloudflare/src/cli/templates/init.ts +++ b/packages/cloudflare/src/cli/templates/init.ts @@ -61,6 +61,9 @@ function initRuntime() { globalThis.__dirname ??= ""; globalThis.__filename ??= ""; + // Some packages rely on `import.meta.url` but it is undefined in workerd + // For example it causes a bunch of issues, and will make even import crash with payload + import.meta.url ??= "file:///worker.js"; // Do not crash on cache not supported // https://github.com/cloudflare/workerd/pull/2434 @@ -95,10 +98,6 @@ function initRuntime() { __NEXT_BASE_PATH__: __NEXT_BASE_PATH__, }); - // Some packages rely on `import.meta.url` (i.e. payload) but it is undefined in workerd - // It cause a bunch of issue, and will make even import crash - // TODO: verify that it won't cause other issues later with other packages - import.meta.url = "file:///worker.js"; } /** From 05c22c2c66fc3ef220ecf737b2ebf6010182eab3 Mon Sep 17 00:00:00 2001 From: Dorseuil Nicolas Date: Tue, 6 May 2025 08:47:51 +0200 Subject: [PATCH 3/3] changeset --- .changeset/soft-rats-punch.md | 5 +++++ packages/cloudflare/src/cli/templates/init.ts | 1 - 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 .changeset/soft-rats-punch.md diff --git a/.changeset/soft-rats-punch.md b/.changeset/soft-rats-punch.md new file mode 100644 index 00000000..bdf53457 --- /dev/null +++ b/.changeset/soft-rats-punch.md @@ -0,0 +1,5 @@ +--- +"@opennextjs/cloudflare": patch +--- + +polyfill import.meta.url diff --git a/packages/cloudflare/src/cli/templates/init.ts b/packages/cloudflare/src/cli/templates/init.ts index 98e476c6..1a95292c 100644 --- a/packages/cloudflare/src/cli/templates/init.ts +++ b/packages/cloudflare/src/cli/templates/init.ts @@ -97,7 +97,6 @@ function initRuntime() { __BUILD_TIMESTAMP_MS__: __BUILD_TIMESTAMP_MS__, __NEXT_BASE_PATH__: __NEXT_BASE_PATH__, }); - } /**