cchryx
(Cchryx)
September 8, 2024, 9:46pm
1
My project is separated with two sub dirs: frontend and backend
The package.json for backend is in the root dir and there is a NextJS for the frontend. When running npm run build locally with this:
"build": "npm install && npm install --prefix frontend && npm run build --prefix frontend"
There is no problems, however when building on vercel there is an error with files not installed:
but they are in package.json in the backend dir:
pawlean
(Pauline P. Narvas)
September 13, 2024, 9:59pm
2
Hi, @cchryx ! Welcome to the Vercel Community.
I think that you need to adjust your Vercel configuration to ensure it correctly installs dependencies for both your frontend and backend. Here’s how you can do that:
Create a vercel.json
file in the root of your project if you haven’t already.
In the vercel.json
file, specify the build command and the output directory. Here’s an example configuration:
{
"version": 2,
"builds": [
{
"src": "package.json",
"use": "@vercel/node",
"config": { "includeFiles": ["backend/**"] }
},
{
"src": "frontend/package.json",
"use": "@vercel/next"
}
],
"routes": [
{ "src": "/api/(.*)", "dest": "backend/api/$1" },
{ "src": "/(.*)", "dest": "frontend/$1" }
]
}
This configuration does the following:
It specifies two build steps: one for the backend and one for the frontend.
The backend build step uses @vercel/node
and includes all files in the backend
directory.
The frontend build step uses @vercel/next
for your Next.js application.
The routes configuration directs API requests to the backend and all other requests to the frontend.
Modify your root package.json
to include a build script that installs dependencies for both frontend and backend:
{
"scripts": {
"build": "npm install && npm install --prefix frontend && npm run build --prefix frontend"
}
}
In your Vercel project settings, make sure the “Build Command” is set to npm run build
.
Set the “Output Directory” to frontend/.next
in your Vercel project settings.
Could you give that a go?
system
(system)
Closed
October 13, 2024, 10:00pm
3
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.