Next build succeeds but it fails to "find a module"?

I got a Next 13 app with Server components, everything was working fine and then I started getting errors on my builds (look at the last line)
...
09:57:35.704 - __next-on-pages-dist__/functions/api/[...path].func.js (esm)
09:57:35.864 ✨ Compiled Worker successfully
09:57:35.936 Found _routes.json in output directory. Uploading.
09:57:35.953 Validating asset output directory
09:57:36.741 Deploying your site to Cloudflare's global network...
09:57:38.765 Parsed 1 valid header rule.
09:57:40.268 Uploading... (31/45)
09:57:40.866 Uploading... (35/45)
09:57:41.007 Uploading... (40/45)
09:57:41.198 Uploading... (45/45)
09:57:41.199 ✨ Success! Uploaded 14 files (31 already uploaded) (1.52 sec)
09:57:41.199
09:57:41.929 ✨ Upload complete!
09:57:43.783 Success: Assets published!
09:57:45.014 Error: Failed to publish your Function. Got error: Uncaught Error: No such module "opt/buildhome/repo/.vercel/output/static/_worker.js/index.js".
imported from "bundledWorker-0.37093777238877634.mjs"
...
09:57:35.704 - __next-on-pages-dist__/functions/api/[...path].func.js (esm)
09:57:35.864 ✨ Compiled Worker successfully
09:57:35.936 Found _routes.json in output directory. Uploading.
09:57:35.953 Validating asset output directory
09:57:36.741 Deploying your site to Cloudflare's global network...
09:57:38.765 Parsed 1 valid header rule.
09:57:40.268 Uploading... (31/45)
09:57:40.866 Uploading... (35/45)
09:57:41.007 Uploading... (40/45)
09:57:41.198 Uploading... (45/45)
09:57:41.199 ✨ Success! Uploaded 14 files (31 already uploaded) (1.52 sec)
09:57:41.199
09:57:41.929 ✨ Upload complete!
09:57:43.783 Success: Assets published!
09:57:45.014 Error: Failed to publish your Function. Got error: Uncaught Error: No such module "opt/buildhome/repo/.vercel/output/static/_worker.js/index.js".
imported from "bundledWorker-0.37093777238877634.mjs"
17 Replies
James
James2y ago
Please can you try deploying using wrangler@3 with npx wrangler@3 pages deploy .vercel/output/static, looks like an issue that was caused by wrangler@2
shixzie
shixzieOP2y ago
The wrangler installed in package.json is v^3.0.1 and the builds are triggered automatically with git commits (Github).
James
James2y ago
Using the Pages Git CI I assume? If so, I believe that uses wrangler@2 when deploying the built application
shixzie
shixzieOP2y ago
Hmm, even if I'm using the v2 beta build environment? even then, shouldn't it use the version specified in the package.json?
James
James2y ago
Good question, not quite sure. Nevertheless, please can you try deploying using wrangler@3 locally?
shixzie
shixzieOP2y ago
my builds are failing locally with the npx @cloudflare/[email protected]
▲ └ chunks/webpack-ba4c49d0b3d07003.js 1.74 kB
▲ ℇ (Streaming) server-side renders with streaming (uses React 18 SSR streaming or Server Components)
▲ ○ (Static) automatically rendered as static HTML (uses no initial props)
▲ Error: Unable to find lambda for route: /contact <----- This route changes every time I run the build

⚡️ The Vercel build (`npx.cmd vercel build`) command failed. For more details see the Vercel logs above.
⚡️ If you need help solving the issue, refer to the Vercel or Next.js documentation or their repositories.
▲ └ chunks/webpack-ba4c49d0b3d07003.js 1.74 kB
▲ ℇ (Streaming) server-side renders with streaming (uses React 18 SSR streaming or Server Components)
▲ ○ (Static) automatically rendered as static HTML (uses no initial props)
▲ Error: Unable to find lambda for route: /contact <----- This route changes every time I run the build

⚡️ The Vercel build (`npx.cmd vercel build`) command failed. For more details see the Vercel logs above.
⚡️ If you need help solving the issue, refer to the Vercel or Next.js documentation or their repositories.
James
James2y ago
Are you on Windows by any chance?
shixzie
shixzieOP2y ago
yes, atm since I'm away from my home machine I can try in a Github Codespace tho
James
James2y ago
Argh, yeah, that'll be why. Vercel's CLI isn't very windows friendly sadly - I actually had to switch to using Ubuntu via WSL because of it :/
shixzie
shixzieOP2y ago
imma try locally deploy on a Github Codespace It "deploys" correctly, I had to create a separate "pages project" since I didn't have a wrangler.toml file I guess, and prob asset uploading is not compatible with the git integration. but back to the original problem, is it that the Pages CI is not using the wrangler specified in the package.json then?
James
James2y ago
I don't think it has any consideration for that when deploying, I believe it just uses the version that the build image has, which at the moment is one of the v2 ones. fwiw, you should be able to choose an existing project when deploying with wrangler
shixzie
shixzieOP2y ago
is there a way to override it? with a env var or flag?
James
James2y ago
You could use the --project-name flag Well you replied to one message and i replied assuming it was the other 😅 I don't think you can change which wrangler the build image uses, but I'm probably not the best person to speak on that
shixzie
shixzieOP2y ago
it does work so I have to manually deploy while there is a way for the CI to use wrangler v3
James
James2y ago
Afraid so at the moment. You could also create a github action to deploy automatically on pushes, using something like https://github.com/cloudflare/pages-action Hopefully at some point in the near future this will no longer be an issue 🙂
shixzie
shixzieOP2y ago
thanks a lot, very fast and helpful MeowHeartCloudflare
James
James2y ago
🙂
Want results from more Discord servers?
Add your server