ask-netlify icon indicating copy to clipboard operation
ask-netlify copied to clipboard

Can I use a yarn monorepo with Netlify?

Open nicwaller opened this issue 6 years ago • 6 comments

About me

  • My name: Nic Waller
  • I've used Netlify: for a few small sites

My question in a little more detail

How can Netlify be used with a yarn monorepo where the package being deployed includes other packages in the same repo?

For example, I am developing a React application with a Serverless backend (deployed to AWS Lambda separately), all in TypeScript. They have a bit of shared code which I've put into the shared directory. My file structure looks like this:

packages/
  backend/
  react-app/
    src/
      index.ts
    package.json
  shared/
    index.ts
    package.json

And netlify.toml looks like this:

[build]
  command = "yarn build"
  base    = "packages/react-app"
  publish = "packages/react-app/dist"

When react-app/package.json contains only globally-resolvable modules from npm, everything works fine. But when I add a dependency on the shared module which is only available locally (not published in npm) I get a missing module error.

1:06:54 PM: npm ERR!
1:06:54 PM:  notarget No matching version found for [email protected]

Does Netlify support this style of monorepo deployment? If yes, is there a guide somewhere, or plans to develop a guide?

Additional comments for Netlify

I'm a huge fan of Netlify. Recently a coworker asked me to help their teenage child set up a website, and I had them up and running with Netlify in under 15 minutes. Quick and painless!

nicwaller avatar Aug 10 '19 20:08 nicwaller

+1 Yeah I'm interested in something similar 👍

alexmacavei avatar Sep 10 '19 06:09 alexmacavei

Any progress here?

seawatts avatar Nov 28 '19 19:11 seawatts

Hate to do this but.... +1

rhinodavid avatar Dec 09 '19 01:12 rhinodavid

For anyone else coming here... You can use Yarn workspaces in a monorepo setup by keeping your base directory set to your project's root directory. This will properly find/link dependencies properly across different package trees as long as your dependencies work in yarn on your local system.

However, this means that if you have multiple sites deploying from the same git repo, you're not able to ignore builds and each site will rebuild even if files in that sub-folder haven't changed. It's not an ideal solution, but it works for now.

[edit] I also discovered a small workaround on another of Netlify's repos that allows you to work more closely to a Yarn/Lerna monorepo setup.

ksaturnius avatar Feb 13 '20 02:02 ksaturnius

same issue still here, pain in the ass to work around.

ganonbit avatar Feb 29 '20 07:02 ganonbit

Maybe this will help.

  1. Link shared in react-app using yarn link
  2. Leave project root as base
  3. Use yarn workspace command for build:
[build]
  command = "yarn workspace react-app build"
  publish = "packages/react-app/dist"

More about yarn workspaces

souljorje avatar Mar 27 '20 09:03 souljorje