CLI to build and develop Next.js apps for Cloudflare Pages
### next-on-pages environment related information System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 24.4.0: Fri Apr 11 18:33:47 PDT 2025; root:xnu-11417.101.15~117/RELEASE_ARM64_T6000 CPU: (10) arm64 Apple M1 Pro Memory: 16 GB Shell: /bin/zsh Package Manager Used: npm (10.9.2) Relevant Packages: @cloudflare/next-on-pages: 1.13.12 vercel: N/A next: N/A ### Description **Description** When deploying a Next.js application (version 13.4.2) using `@cloudflare/next-on-pages` (version 1.13.12, based on build logs) to Cloudflare Pages, the build process completes successfully, but the deployed application fails at runtime with a 500 error. The runtime logs show the following error: `Error: No such module "__next-on-pages-dist__/functions/async_hooks". imported from "__next-on-pages-dist__/functions/index.func.js"` This issue occurs even after resolving a separate build-time error (`ReferenceError: queueMicrotask is not defined`) which was caused by `framer-motion`. `framer-motion` has been completely removed as a dependency and all its usages have been commented out, leading to successful builds. However, the `async_hooks` runtime error persists, suggesting it's an underlying issue with how Next.js is adapted for the Cloudflare Pages environment by `@cloudflare/next-on-pages`. All dynamic pages and API routes are using `export const runtime = 'experimental-edge';`. ### Reproduction **Reproduction** 1. **Project Setup:** * Create a Next.js project using version `13.4.2`. * Install `@cloudflare/next-on-pages` (version `1.13.12` was used in the failing deployment). 2. **Configuration for Cloudflare Pages:** * Set up `wrangler.toml` if necessary (e.g., if customizing `pages_build_output_dir`. In my case, it was `pages_build_output_dir = ".vercel/output/static"` though the error persisted even when this was not explicitly set and letting the Vercel build output normally). * Ensure the build command in Cloudflare Pages is `npm run build` (or your project's equivalent, e.g., `npx vercel build`). * Ensure relevant pages/API routes intended for Edge runtime use `export const runtime = 'experimental-edge';`. 3. **Initial `framer-motion` Issue (Potentially Related Context):** * If `framer-motion` (or a library with similar client-side scheduling) is used, a build error `ReferenceError: queueMicrotask is not defined` might occur. This was resolved by completely removing `framer-motion` from `package.json` and commenting out all its usages. 4. **Deployment:** * Deploy the application to Cloudflare Pages. The build should succeed. 5. **Runtime Error:** * Access any page of the deployed application. * A 500 Internal Server Error is returned. * The Cloudflare Functions logs show: `Error: No such module "__next-on-pages-dist__/functions/async_hooks". imported from "__next-on-pages-dist__/functions/index.func.js"`. **Relevant Log Snippet (Runtime):** ```json { "outcome": "ok", "scriptName": "pages-worker--xxxx-production", // Example "exceptions": [], "logs": [ { "message": [ "Error: No such module \"__next-on-pages-dist__/functions/async_hooks\".\n imported from \"__next-on-pages-dist__/functions/index.func.js\"" ], "level": "error", "timestamp": 1747317962607 // Example timestamp } ], "eventTimestamp": 1747317962511, // Example timestamp "event": { "request": { "url": "https://your-deployment-url.pages.dev/", // Example "method": "GET" // ... other request details }, "response": { "status": 500 } } } ``` โ ๏ธ **Important Note:** Unfortunately, the project experiencing this issue is in a private repository. I will try to create a minimal public reproduction if time permits. The key elements seem to be Next.js `13.4.2` and `@cloudflare/next-on-pages` `1.13.12` with Edge runtime. ### Pages Deployment Method Pages CI (GitHub/GitLab integration) ### Pages Deployment ID 78a9652e-4044-4c77-b08a-4978d787a9ae ### Additional Information spent around 1 week and $400 in cursor credits. gave up. seriously sad. ### Would you like to help? - [ ] Would you like to help fixing this bug?
This issue appears to be discussing a feature request or bug report related to the repository. Based on the content, it seems to be still under discussion. The issue was opened by hotairbag and has received 0 comments.