After updating to 9.5, next no longer works in my current monorepo setup on a deployment to vercel. Everything appears fine in development, however once I deploy to vercel the issue is exhibited by the home page redirecting to a path identical to the routing setup to the routes field in the now.json. In this case, the homepage is redirected to /my-app
Here is a link to the reproduction: https://github.com/stevez86/next-repro-2
And a link to a deployment: https://my-app-nsgjc5j8l.vercel.app/
Here is my now.json file, which I think is the culprit. The other app routes appear to be working as intended ie /abc/:slug1/:slug2 so I think this is only applicable to the homepage route at "/".
{
"version": 2,
"builds": [{ "src": "my-app/next.config.js", "use": "@now/next" }],
"routes": [{ "src": "/(.*)", "dest": "/my-app/$1", "continue": true }]
}
We're seeing this as well. Similar setup.
I removed "continue": true and it seems to work, but it's very weird issue and sometimes it seems to linger in browser cache. Will report back if this didn't solve it.
Turn out that removing "continue": true introduced new issues, so we simply solved this better by moving away from routes to rewrites in our now.json file.
@fredrik-sogaard Interesting. Mind providing an example?
Same, an example would be great. Im having issues with being able to use a catch all, its overriding my other rewrites
This worked for us:
"rewrites": [
{
"source": "/backend",
"destination": "packages/backend/src/index.ts"
},
{
"source": "/(.*)",
"destination": "packages/frontend/$1"
}
],
@timneutkens Is this an issue with Next or Now? Should I be doing monorepo routing differently or is the rewrites method the way we should be handling this?
From what I could gather, rewrites is the way forward.
We only encountered the bug when upgrading from Next 9.4 to 9.5 and deployed to Vercel, so I'm guessing it's both a Vercel and Next issue?
Are you able to run that with vercel dev? For me, that "/(.*)" will catch all the routes including /backend
Haven't tried with vercel dev but we're running this setup on a production site now on Vercel.
Can you share your now.json file?
Yes, thanks for helping:
{
"version": 2,
"build": {
"env": {
"BUILDING_FOR_NOW": "true"
}
},
"builds": [
{ "src": "packages/clubs/package.json", "use": "@vercel/next" },
{ "src": "packages/books/package.json", "use": "@vercel/next" }
],
"rewrites": [
{ "source": "/books(.*)", "destination": "/packages/books$1" },
{ "source": "/(.*)", "destination": "/packages/clubs/$1" }
]
}
If I remove the second rewrite, the first one works. The app follows the multi-zones setup but im trying to use rewrites instead of routes and I have two nextjs apps under a packages directory.
Using a negative lookahead also causes the first route to be rewritten to the wrong package:
{ "source": "/((?!books).*)", "destination": "/packages/clubs/$1" }
I figured it out:
{ "source": "(/(?!packages).*)", "destination": "/packages/book-clubs$1" }
The previous routes were rewritten to /packages, so the catch all route needs to have a negative lookahead to not catch the previous rewrites.
Hello,
We don't recommend attempting to make monorepos work via a vercel.json file — it's simply a pain attempting to make the routing work.
We are testing Monorepo Support internally without the need for a vercel.json file. Stay tuned for an announcement in the coming days!
We're having the same issue after updating to Next.js 9.5. But we don't use Vercel for deployments. It works fine on local dev mode. It breaks on home showing 404 once we deploy in our servers. Which may mean the bug happens on next build or next start?
@samsisle Very Interesting! Any rough idea when that example will be released?
@stevez86 It was released! → https://vercel.com/blog/monorepos 🎉
Most helpful comment
@stevez86 It was released! → https://vercel.com/blog/monorepos 🎉