20 days ago
Hi Guys!
I’m deploying a Next.js 14 app to Railway from a monorepo setup:
/root
/frontend ← Next.js app
/backend ← separate API
I’ve tried two approaches and both fail:
1. Using railway.toml in the monorepo root
[build]
builder = "NIXPACKS"
buildPath = "frontend"
buildCommand = "cd frontend && npm install && npm run build"
[start]
runDir = "frontend"
cmd = "npm run start"
But the build fails with errors like:
Module not found: Can't resolve '@/lib/navigation'
This happens for any alias imports like @/lib/api, even though everything works locally.
My frontend/tsconfig.json includes:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
}
}
2. Deploying from the frontend/ folder directly, using Docker
I set the Railway project root to frontend/, added a custom Dockerfile, and still ran into the same module resolution issue with the @ alias.
Everything works fine locally — the issue only happens during Railway builds.
Question:
How can I get Railway (with Nixpacks or Docker) to correctly resolve @ aliases in a monorepo Next.js project?
Any working example or guidance would be appreciated.
Thanks!!
1 Replies
19 days ago
This only happens with import alias related to the backend application ?
How have you setup the monorepo, workspaces ?