Hi,
I have a monorepo setup:
repo
- package.json
- BUILD.bazel
- source/
- frontend/
- BUILD.bazel
- next.config.js
- app/
- page.tsx
- layout.tsx
- BUILD.bazel
I manage to build this using bazel and run it locally without issues (e.g. bazel run source/frontend:next
).
I can also build the project fine: bazel build source/frontend:next
builds fine and creates a .next
folder under bazel-bin/source/frontend/.next
. This is all expected and working fine.
The problem is when I try to deploy this to vercel. I want to build locally and deploy the prebuilt artifacts, so my plan is to do
vercel build --prod && vercel deploy --prebuilt --prod
However, I am having trouble deploying the right files to vercel. My project.json file looks like this:
{
"projectId": "...",
"orgId": "...",
"settings": {
"createdAt": 1728198914318,
"framework": "nextjs",
"devCommand": null,
"installCommand": "",
"buildCommand": "bazel build //source/frontend:next",
"outputDirectory": "bazel-bin/source/frontend/.next",
"rootDirectory": null,
"directoryListing": false,
"nodeVersion": "20.x"
}
}
The buildCommand executes and is successful, but the CLI then fails with Cannot find module 'next/dist/server/next-server.js'
. I tried adding this next
folder in many places (under .vercel/builders/node_modules
, as a first level dir under the root, inside source/frontend
, etc. - but to no avail). If I change the rootDirectory to be source/frontend
, then I won’t have access to the build output, since bazel puts it into bazel-bin
, two layers above the source/frontend
dir - and from the docs, it looks like you cannot access anything upstream of the root dir, not even using ..
to navigate back.
If I change framework choice to other
, then vercel build
command finishes successfully and the project is deployed to vercel, vercel does not run it properly (it raises a 404 Error - presumably because the files are not in the right format).
Ok so what is the solution here? How does one deploy a pre-build .next
folder to vercel using the CLI ?