Skip to content

Commit a7bf738

Browse files
shim next/dist/compiled/node-fetch (#422)
currently in our bundle we include the `next/dist/compiled/node-fetch` package, this doesn't seem actually necessary and it introduces a good amount of unnecessary code in our bundle, moreover it also causes a warning in the terminal (because of an === -0 comparison), the changes here replace the node-fetch code with a simply shim that re-exports the native fetch
1 parent d3c6533 commit a7bf738

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

packages/cloudflare/src/cli/build/bundle-server.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ export async function bundleServer(buildOpts: BuildOptions): Promise<void> {
104104
],
105105
external: ["./middleware/handler.mjs"],
106106
alias: {
107+
// Note: it looks like node-fetch is actually not necessary for us, so we could replace it with an empty shim
108+
// but just to be safe we replace it with a module that re-exports the native fetch
109+
// we do this to both save on bundle size (there isn't really any benefit in us shipping the node-fetch code)
110+
// and also get rid of a warning in the terminal caused by the package (because it performs an === comparison with -0)
111+
"next/dist/compiled/node-fetch": path.join(buildOpts.outputDir, "cloudflare-templates/shims/fetch.js"),
107112
// Note: we apply an empty shim to next/dist/compiled/ws because it generates two `eval`s:
108113
// eval("require")("bufferutil");
109114
// eval("require")("utf-8-validate");
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default fetch;

0 commit comments

Comments
 (0)