ask-netlify
ask-netlify copied to clipboard
Can I use a yarn monorepo with Netlify?
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!
+1 Yeah I'm interested in something similar 👍
Any progress here?
Hate to do this but.... +1
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.
same issue still here, pain in the ass to work around.
Maybe this will help.
- Link
sharedinreact-appusing yarn link - Leave project root as base
- Use yarn workspace command for build:
[build]
command = "yarn workspace react-app build"
publish = "packages/react-app/dist"
More about yarn workspaces