I’m trying to deploy multiple sites from an Nx monorepo that has one
package.json at the root. The problem is that setting a base directory for each site is causing Netlify to skip installing the npm dependencies, causing the builds to fail.
I’ve set up an isolated reproduction of the issue at GitHub - lourd/nx-test, connected to the sites
agitated-next-e512a6. The repo has a Next.js app at
apps/my-next-app and a client-rendered React app at
apps/my-react-app. Each of those directories has a
netlify.toml in them. In the Netlify UI, each site has their base directory set to their respective directory in
Here’s a link to a failing build of the Next.js app, and a link to a failing build of the React app. They both fail with an error related to the fact that no npm dependencies are being installed during the build process.
I tried working around this by 1. adding
yarn install to the build command, and 2. calling
yarn install as part of the
onPreBuild event in a custom build plugin. Those workarounds worked for the React app, but not for the Next.js app. That’s because the Next.js app also uses the
@netlify/plugin-nextjs build plugin, and it tries to install the plugin before running any of the build plugins, regardless of the order they’re listed in the config file. This causes a
Dependencies installation error error:
npm ERR! notarget No matching version found for @netlify/plugin-nextjs@4.`
Here's the Next.js app's netlify.toml:
[build] publish = "../../dist/apps/my-next-app/.next" command = "nx build my-next-app" [build.environment] PROJECT_NAME = "my-next-app" NETLIFY_USE_YARN = "true" [[plugins]] package = "../../tools/netlify-plugins/force-install" [[plugins]] package = "../../tools/netlify-plugins/only-build-when-affected" [[plugins]] package = "@netlify/plugin-nextjs"
I tried to reproduce the issue locally using the Netlify CLI/dev environment, but the builds succeed when doing that .
Thanks in advance for your help!