diff --git a/packages/cloudflare/src/cli/build/bundle-server.ts b/packages/cloudflare/src/cli/build/bundle-server.ts index b2c6b366..baa1a696 100644 --- a/packages/cloudflare/src/cli/build/bundle-server.ts +++ b/packages/cloudflare/src/cli/build/bundle-server.ts @@ -104,6 +104,11 @@ export async function bundleServer(buildOpts: BuildOptions): Promise { ], external: ["./middleware/handler.mjs"], alias: { + // Note: it looks like node-fetch is actually not necessary for us, so we could replace it with an empty shim + // but just to be safe we replace it with a module that re-exports the native fetch + // we do this to both save on bundle size (there isn't really any benefit in us shipping the node-fetch code) + // and also get rid of a warning in the terminal caused by the package (because it performs an === comparison with -0) + "next/dist/compiled/node-fetch": path.join(buildOpts.outputDir, "cloudflare-templates/shims/fetch.js"), // Note: we apply an empty shim to next/dist/compiled/ws because it generates two `eval`s: // eval("require")("bufferutil"); // eval("require")("utf-8-validate"); diff --git a/packages/cloudflare/src/cli/templates/shims/fetch.ts b/packages/cloudflare/src/cli/templates/shims/fetch.ts new file mode 100644 index 00000000..709bc440 --- /dev/null +++ b/packages/cloudflare/src/cli/templates/shims/fetch.ts @@ -0,0 +1 @@ +export default fetch;