I have the following folder structure that I want to make a monorepo using yarn:
/root
/apps
/app-one
/app-two
/packages
/ui
I want that only the root/packages/* modules can be used by apps/* projects. Meaning I don't want that apps/app-one can use a module of apps/app-two. root/apps/* can only use modules from root/packages/*,
So I don't want that root/node_modules can possibly contain any module exported from root/apps/*.
The problem is when I do yarn install inside root/apps/app-one I get the following error:
Problem
I understand that yarn couldn't link that packages to any remote node module or local module using symlink. But how to achieve what I want If it does not support that ?
What I did:
I initialized yarn using yarn init inside the root/ folder. I updated the root package.json to the following:
{
"private": true,
"name": "test",
"version": "1.0.0",
"packageManager": "[email protected]",
"workspaces": [
"packages/*"
]
}
In root/packages/ui/:
1- I did yarn init
2- I created a index.js file with this content: export const A = 22;
3- I changed the package.json to:
{
"name": "ui",
"version": "1.0.0",
"packageManager": "[email protected]"
}
In root/apps/app-one:
1- I did yarn init
2- I changed the package.json to:
{
"name": "app-one",
"packageManager": "[email protected]",
"dependencies": {
"ui": "*"
}
}
3- I created a index.js file with this content: import {A} from 'ui'
4- Following the error message after doing yarn install i added an empty yarn.lock file for this to be treated as a seperate project.
error
Also for the modules to be installed in node_modules I added the following .yarnrc.yml file inside root/ and root/apps/app-one: nodeLinker: "node_modules"
This is the final folder structure: folder structure