-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Monorepo and Nx support #433
Comments
this writeup is 🔥 . thanks for putting it together! :) thoughts on the possible solutions:
if we go the route of |
Great write-up indeed, thanks for that. If I may, I will add another weird scenario onto the pile of oddities: I have replaced lerna with yarn workspaces (simpler for my use case) and got the following set up: netlify.toml [build]
base = "/web/"
publish = "/web/"
command = "yarn build"
[[plugins]]
package = "@netlify/plugin-nextjs"
next.config.js const nextConfig = {
reactStrictMode: true,
target: 'serverless',
}; Netlify UI Deploy config
Build log7:25:14 PM: Different build dir detected, going to use the one specified in the Netlify configuration file: 'web' versus '/web' in the Netlify UI
7:25:14 PM: Different publish path detected, going to use the one specified in the Netlify configuration file: 'web/web' versus '' in the Netlify UI
...
7:26:16 PM: ────────────────────────────────────────────────────────────────
7:26:16 PM: Netlify Build
7:26:16 PM: ────────────────────────────────────────────────────────────────
7:26:16 PM:
7:26:16 PM: ❯ Version
7:26:16 PM: @netlify/build 12.6.0
7:26:16 PM:
7:26:16 PM: ❯ Flags
7:26:16 PM: deployId: 60d31a0f43c7f9149616ca17
7:26:16 PM:
7:26:16 PM: ❯ Current directory
7:26:16 PM: /opt/build/repo/web
7:26:16 PM:
7:26:16 PM: ❯ Config file
7:26:16 PM: /opt/build/repo/web/netlify.toml
7:26:16 PM:
7:26:16 PM: ❯ Context
7:26:16 PM: production
7:26:17 PM:
7:26:17 PM: ❯ Loading plugins
7:26:17 PM: - @netlify/plugin-nextjs@3.4.2 from netlify.toml
...
7:27:05 PM: ────────────────────────────────────────────────────────────────
7:27:05 PM: 6. Deploy site
7:27:05 PM: ────────────────────────────────────────────────────────────────
7:27:05 PM: Starting to deploy site from 'web/web' Note the reference to a folder called `'web/web' which my project does not have.... And the pipe was successful 🤷🏼 Edit: note, if this is the wrong place to post the above, happy to move if you let me know how/where you want it :) |
The issue is that "publish" is relative to "base". You should usually leave it alone, and it will default to "out" for Next.js sites |
I am using |
Yes, that's where the build plugin should be putting it |
I have a draft PR that implements option 4. It needs testing with Nx sites particularly, though I'd like tests from other monorepo types too eventually. Instructions on trying it out here: #434 |
@pzi i believe i'm not sure though, are you saying the build/deploy works when you say "the pipe was successful"? |
Yes, sorry. The build & deploy worked 😬 which felt odd because of the |
I will try and use the above WIP @ascorbic I am just mindful that I am on a free plan and I am burning through my build minutes. All these trial & error commits, builds sucked up 1/3 of my allocation 😅 I finally got a stable build & deploy again, albeit using yarn workspaces instead of lerna. However, I wonder if there is another variable that may need to be considered when dealing with mono repos: I had a bunch of "nothing" deploys because I don't have a
So, if I don't set any deploy config via UI, it results in "nothing" deploys. If I change the UI base dir to /web and /studio respectively, CI picks up the right toml files and "additionally" uses them, so everything is then based on base dir of the UI plus the base in the toml file resulting in PS: Probably should mention that I have set up 2 sites (1 for studio and 1 for web) |
Fixed in #434 |
Hi @ascorbic , I'm not sure to fully understand how I'm supposed to setup my nx monorepo for deploying nextjs apps with netlify. Here is my file structure:
On netlify UI, I've setup
When deploying, i've got the follow error:
What am I missing here? |
Hi @KevTale |
* fix: disable regional blobs until feature is ready for release * test: Update tests to not include the experimental region flag
Currently we can only handle monorepos if the Next site root directory (that contains
next.config.js
) can be set asbase
in thenetlify.toml
or UI. This means that it needs a package.json that installs all dependencies. It either needs to be self-contained, or it needs to be in a yarn workspace. This is because of the way Netlify handles monorepos.The workaround of prepending
cd the/site/root
before the build command does not currently work for Next sites, because build plugins always run from the base directory, meaning the plugin can't find all the Next files. This also doesn't work for monorepos that need commands to be run from the root. This is a particular problem for Nx sites, as they have no way of running commands from the app directory.When building a Next site, the build plugin needs to know two things:
next.config.js
. Currently the plugin assumes this iscwd()
: i.e. thebase
. This is why thecd
workaround fails.distDir
(i.e. the.next
directory). In most cases we can find this out from the config at 1. The exception is with Nx, which I'll cover more below.Information that can be set by the user:
base
dir, which is currently where we assumenext.config.js
is, and where we run the build command.out
, and is where we move the files fromdistDir
.distDir
, which is set innext.config.js
. By default this is.next
, except with Nx, which rewrites it on the fly unless it has been changed by the user to something else, in which case it's left alone.Possible solutions:
next.config.js
is in its parent directory. From this we can find thedistDir
.distDir
can't be found from thenext.config.js
. Both of the are the case by default with Nx, which changes distDir on the fly to a directory outside of the site root.distDir
can't be found from the config.distDir
to a specific value, which overrides the behaviour where it rewrites it to a parent directory that we can't work out.Monorepo types
The following project types have been tested
The text was updated successfully, but these errors were encountered: