I decided to use monorepo for my new project.
After a few months of using I need to tell you that it was a really great choice.
Meanwhile, I had just one problem and it was with duplicates in the final build.
Especially with React package. I saw too many times Invalid Hook Call Warning. When I was digging more I found comment: You might have more than one copy of React in the same app. (https://reactjs.org/warnings/invalid-hook-call-warning.html)
First of all, I tried to fix it with Webpack (aliases, resolve) but it started to be unmaintainable with new packages.
Then I found parameter --hoist. It will put all shared(duplicate) dependencies from all your packages into your root node_modules directory.
Rollup with Babel will start to work out of the box. You just need to set up Webpack resolve.modules. Here is my example of webpack.config.babel.js located in the root directory of each package.
resolve: {
modules: [
path.resolve(__dirname, 'node_modules'),
path.resolve(__dirname, '../../node_modules'),
'node_modules',
],
...
For more information check out Lerna documentation:
https://github.com/lerna/lerna/blob/master/doc/hoist.md
FYI: I wanted to work with pure NPM and not to use YARN workspaces.
I still don’t understand with the benefit of monorepo and can’t relate with it. That’s why I don’t use monorepo and prefer to use multi repo. Perhaps you have great references that I can read 😀
Why do you want to avoid yarn workspaces? I find it much easier to use.
Hi @dannychickenegg. Actually I like YARN and I am glad that they created it. I think that it was the main reason why they updated NPM faster :)
I have two answers: