Inside my Monorepo I have one packages in which I want all the dependencies inside its node_modules.
But whatever I do, it's node_modules remains empty.
So, for the purpose of my question I was able to reproduce the issue with the following setup
/
package.json
lerna.json
node_modules
packages/
A/
node_modules
package.json
index.ts
B/
node_modules
package.json
index.ts
I've created a repo for this!
Main package.json
{
"name": "A-B-test",
"private": true,
"workspaces": {
"packages": ["packages/*"],
"nohoist": [ "**/B" ]
},
...
"devDependencies": {
"lerna": "^3.13.4"
}
}
B/package.json
looks like
{
"name": "@scaljeri/B",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"angular": "^1.7.8"
},
"devDependencies": {
"browserify": "^16.2.3",
"typescript": "^3.5.2"
}
}
Now when I run yarn
in the root of the project, all dependencies are installed in the root node_modules
.
yarn version: 1.16.0 node: 12.4.0
Any suggestions what might be the problem?
This calls for using nohoist , which will put all of the packages we specify into the local node_modules for that package and not hoist them into the root workspace package. json.
Yarn Workspaces is a feature that allows users to install dependencies from multiple package. json files in subfolders of a single root package. json file, all in one go. Yarn can also create symlinks between Workspaces that depend on each other, and will ensure the consistency and correctness of all directories.
yarn link is a command that helps during the development of npm packages. It links a local npm package to an existing project that uses yarn package manager. What this does is that it removes the need to create a new example project to test your npm package in development.
In my experience, it has been necessary to doubly specify each package in the following manner:
{
"nohoist": [
"**/B",
"**/B/**",
"**/C",
"**/C/**"
]
}
In addition, I have found it necessary to delete all existing node_modules
folders after modifying the nohoist
settings. So, if your projects are in packages
, and you are in your project directory, you can delete all of those node_modules
folders like this:
# delete node_modules on linux
rm -rf ./packages/*/node_modules
rm -rf ./node_modules
# install again
yarn install --check-files
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With