Monorepo support not working

Hey @colindavey,

I could get it working this time. No kidding. here’s the repo:

https://github.com/Hrishikesh-K/chess

So, firstly, I changed the components package name to avoid ambiguity, but yeah that’s about it.

My build command is cd packages/chess-game && yarn build and publish directory is packages/chess-game/build.

I’m not sure what exactly was the cause of this being successful, might as well be the inclusion of the dist directory.

Thanks @hrishikesh! Sorry for the late reply, and I’ll need a couple of days before I’ll be able to check it out.

I’ll let you know what I find!

Did you got solution. Actually i’m facing same issue on my end and that’s why i mention you here. I am getting error while creating website.

@lenadavids, I have some workarounds, but need to follow up on something before I can suggest something specific.

@lenadavids,

If you could mention what your error is, we could possibly work out a solution for you too.

@hrishikesh @lenadavids I’ve had a chance to checkout hrishikeh’s solution, which has clarified what is going on for me. However, it seems off to have to put items that can get built into the repo. So, I have come up with this solution:

Base directory: /
Publish directory /packages/chess-game/build/

But this is the main thing:

Build command: cd packages/components && yarn build && cd ../chess-game && yarn build

With that setup, it works, and I do not have to put built things into the repo.

The first thing I wanted to check was whether, when running locally, yarn install is sufficient to get it to work. It isn’t. Locally, I still have to yarn build the components as well. So, that is what has to happen on Netlify too.

Then, the next question is, what about the doc Monorepos | Netlify Docs? I believe that doc should reflect the above.

The section Base directory versus cd seems off with regard to this case, as do the discussions regarding project structures with apps and shared components in the same monorepo. I’m not sure exactly when it’s right to give the root as the base directory combined with cd, versus setting it to the directory with your app. But the cd approach with builds for all the shared components seems necessary for projects with the app(s)/shared-component(s) structure.

I’m thinking that the rule of thumb might be if the package doesn’t depend on other packages in your monorepo, then use the package dir as the base dir, otherwise you need the cd approach. What do you think?

I think your last reply sums it up pretty much correctly, at least from what I’ve understood from all the experimenting and there seems to be a reasonable explanation for that.

When you set base directory to your website’s folder, Netlify won’t be reading any of the folders above that level, and thus, would fail to install the component from the repo (as npm will search for it in the registry and it won’t exist there - an important reason to have a unique name for the package). However when you set the base directory to the room and use workspaces, npm or yarn is able to read the entire repo, all of the package.jsons within it and manage the module resolution accordingly. So once all the modules are installed, you can cd into the directory you want to build and that should do it.

IMO this should be the default behavior, or at least there should be a simple option to disable the context isolation during builds in a monorepo. It’s fairly common for sites in monorepos to import other packages in the monorepo, after all.

1 Like

It’s been over a year since that post and monrepos work a bit better at this point. Are you having any specific error that we can help with?

[react- cra TSX-worspace npm/lerna]

Errors

10:53:46 AM: git clone --filter=blob:none https://github.com/c0ncentus/atalante

10:53:46 AM: Preparing Git Reference refs/heads/feanaro

10:53:47 AM: Parsing package.json dependencies

10:53:48 AM: No build steps found, continuing to publishing

10:53:48 AM: Failing build: Failed to build site

10:53:48 AM: Failed during stage ‘building site’: Deploy directory ‘app/feanaro/build’ does not exist

10:53:49 AM: Finished processing build request in 3.329s

It should work ?

proof on github that build exist in the path mention (app/feanaro/build) (only one branch so I cannot be wrong)

If i put all dependencies in feanaro’s package .json =>
Why i use monorepo ? I delete 3 GB for putting react package and co on commun workspace lol.
Are you sure Netlify support monorepo ? (including commun package.json)

Proposition - Legacy

It will be more helpfull at least Netlify made special attribute on package.json that override package.json’s dependencies and then make all operations …

Anyway

can you help with any clue ?
I dont have many good alternative : /

hi @c0ncentus

You don’t seem to have a build command set up:

You need to add this to match your local build command, I believe that’ll make it work :slight_smile:

I have already test a lot with “build command”
=> have issue with shared components packages, don’t “find” it (publish and available on npm, maybe on conflict with reference on tsconfig.json).

Maybe there is a config file for solving this but want esiest solution as possible,

Netlify have error when build, but locally not, so … there is a solution for sending “build folder” as “already build” ?
maybe not “modern” and too legacy but garentee to publish something and avoid weird behaviour…

Not quite sure where you’re trying to go here but may I recommend that you read through our monorepo docs and try to set things from the beginning on a new site perhaps?

I read the doc many times but dont understand where to mention my package(shared components) reference

site-1 netlify.toml

[build]
command = “gatsby build”
functions = “functions”
publish = “public”

[build.environment]
SITE1_SPECIFIC_FLAG = “true”

[[plugins]]
package = “@netlify/plugin-lighthouse”

I found that but i dont really know how it helps me : /

the doc dont me help at all … dont know what to do (i read many times …).

I have already my “workspaces”.

  • “app” folder contain all apps
  • “package” folder contain shared components.

I will test that but I guess i will have the same error …

[build]
  # Directory to change to before starting a build.
  # This is where we will look for package.json/.nvmrc/etc.
  base = "/"

  # Directory (relative to root of your repo) that contains the deploy-ready
  # HTML files and assets generated by the build. If a base directory has
  # been specified, include it in the publish directory path.
  publish = "./build"

  # Default build command.
  command = "yarn run build"

# The following redirect is intended for use with most SPAs that handle routing internally.
[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200

If tools will be clever … but not nowadays : /

I would suggest that to activate our monorepo support, you’d use a base directory of apps/ or packages/ - depending on what site you are trying to build. The usual way that folks lay out their monorepos is to “group” all the assets for the site into a subdirectory - and then start their build there (which the base setting does! - so if you have many sites under apps/ - you’d set apps/site1 or something like that as base).

Please let us know how it goes in that configuration!