How to fix "Invalid alias name" error when deploying Next.js app to Cloudflare

I was trying to deploy a Next.js app to Cloudflare when I encountered an error saying Invalid alias name. The error was related to the OpenNext library. More specifically:

Error: Build failed with 3 errors:
error: Invalid alias name: "next/dist/compiled/edge-runtime"
error: Invalid alias name: "next/dist/compiled/node-fetch"
error: Invalid alias name: "next/dist/compiled/ws"

I couldn't find any information about this error, probably because OpenNext was originally created for AWS, not Cloudflare Pages. The Cloudflare integration was only added a few months ago, so it's quite new.

Finally, I found a somewhat similar issue that a few people had encountered, and they resolved it by deleting or downgrading esbuild from their package.json. However, I didn't have esbuild in my package.json at all, so I gave up on that idea after trying for a while.

Then I decided to investigate what was the node-fetch dependency from. I didn't have it explicitly defined in my package.json, but it was present in my dependencies. To check where it was coming from, I ran pnpm why node-fetch:

> pnpm why node-fetch
Legend: production dependency, optional only, dev only
 
devDependencies:
@cloudflare/next-on-pages 1.13.12
└─┬ vercel 42.1.1 peer
  ├─┬ @vercel/fun 1.1.6
 └── node-fetch 2.6.7
  ├─┬ @vercel/next 4.7.11
 └─┬ @vercel/nft 0.29.2
   └─┬ @mapbox/node-pre-gyp 2.0.0
     └── node-fetch 2.7.0
  ├─┬ @vercel/node 5.1.16
 ├─┬ @vercel/nft 0.29.2
 └─┬ @mapbox/node-pre-gyp 2.0.0
   └── node-fetch 2.7.0
 └── node-fetch 2.6.9
  ├─┬ @vercel/redwood 2.3.1
 └─┬ @vercel/nft 0.29.2
   └─┬ @mapbox/node-pre-gyp 2.0.0
     └── node-fetch 2.7.0
  └─┬ @vercel/remix-builder 5.4.7
    └─┬ @vercel/nft 0.29.2
      └─┬ @mapbox/node-pre-gyp 2.0.0
        └── node-fetch 2.7.0

It pointed to @cloudflare/next-on-pages, which was no longer used or needed (a remnant from an old setup). I removed it, and that fixed the entire issue.


Published on May 29, 2025 2 min read