In full transparency I have created this issue here because Netlify forum won't let me post more then 1 media link on an issue and I wanted to provide additional details to the issue. That post can be found here.
Problem:
Deploying monorepo application via Netlify CLI results in "Not Found error" due to not picking up the @netlify/plugin-nextjs
plugin for nextjs runtime but works correctly via UI production deployments.
Required info:
- Repo: pr-with-deployment-issue
- Site with error deployment: https://63bc6cdb745e5c0d82dcc4eb--webbsite-dev.netlify.app/
Deployment settings:
Background:
Our team is using both Netlify CLI / GitHub Actions and the UI to deploy a Netlify site. The deployment via GitHub Actions is for development previews and deployments via Netlify UI is for our staging environment. We prefer making use of Netlify CLI / GitHub Actions for flexibility in our dev previews. You can see that workflow here.
UI Deployment that works:
The deployments via the UI works perfectly fine with the installed next.js runtime. You can see that deployment here. It correctly processes rules, edge functions and runtime usage.
Netlify CLI / GitHub Action deployment that does not work:
Deploying the site using Netlify CLI and the @netlify/plugin-nextjs
plugin does not work as intended. Deployment steps used:
- Install @netlify/plugin-nextjs as dev dependency
- Create
netlify.toml
file with following contents:
[[plugins]]
package = "@netlify/plugin-nextjs"
[build]
command = "yarn build:webbsite"
publish = "./dist/apps/webbsite/.next"
- Run
netlify deploy context=deploy-preview site=$NETLIFY_WEBBSITE_ID --dir=./dist/apps/webbsite/.next
Successfully deploys the site:
BUT....
AND...
Expected Result
I want to be able to trigger dev-preview deployments using the Netlify CLI that correctly deploy the site with nextjs runtime AND keep the working as intended deployment via the UI for production deployments. If the netlify.toml
must be used, ideally I would like that to exist in the specific apps subdirectory.
Also the GH workflow works fine for all other next.js / netlify deployments that do not depend on next.js runtime usage.
Any help would be greatly appreciated as I have exhausted all documentation / resources to this point. Thanks!
Solution:
Needed to add
--build
flag in my deployment command.netlify deploy --build context=deploy-preview site=$NETLIFY_WEBBSITE_ID --dir=./dist/apps/webbsite/.next
For those, like me, who needed to deploy from root but needed a
netlify.toml
config file to live in the package/subdir. During the GH action workflow I just added a step to copy anetlify.toml
config from package/subdir (e.g.package/app1
) to root prior to executing deployment command mentioned above.