Hey there,
My team has a monorepo manage with Nx. We have two apps that we’re trying to deploy on Netlify as two separate sites. One app is a static, client-rendered React application; the other is a new Next.js app using Next.js v12. I’m having trouble figuring out how to setup continuous deployment for both of them.
We have our monorepo setup as such:
/
netlify.toml
package.json
apps/
my-nextjs-app/
next.config.js
my-react-app/
libs/
shared-lib-between-the-apps/
In the netlify.toml
we have:
[[plugins]]
package = "@netlify/plugin-nextjs"
We’re using the beta v4 Essential Next.js plugin, as specified in our package.json
"scripts": {
"serve": "nx serve",
"build": "nx build",
},
...
"devDependencies": {
"@netlify/plugin-nextjs": "^4.0.0-beta.6",
...
"nx": "^13.1.3",
...
}
On our Netlify site for the Next.js app, we specify our build command as yarn nx build my-nextjs-app
and the publish directory as dist/apps/my-nextjs-app/.next
. This works and deploys that site just fine.
The problem I have reveals itself when deploying the other site, the one that isn’t a Next.js app. On that one, the build command is set as yarn nx build my-react-app
and the publish directory as dist/apps/my-react-app
. Its build process simply spits out a bunch of static files and relies on client-side routing. When Netlify goes to deploy that, it fails because the Next.js build plugin expects a Next.js build:
3:44:07 PM: ────────────────────────────────────────────────────────────────
3:44:07 PM: Plugin "@netlify/plugin-nextjs" failed
3:44:07 PM: ────────────────────────────────────────────────────────────────
3:44:07 PM:
3:44:07 PM: Error message
3:44:07 PM: Error: The directory "dist/apps/my-react-app" does not contain a Next.js production build. Perhaps the build command was not run, or you specified the wrong publish directory.
How can I resolve this? Can I have app-specific netlify.toml files somehow? Or is there something else I could to do workaround the issue?
Thanks in advance for your help!