I am trying to implement yarn workspaces + lerna into my project. I have a simple structure:
--package.json
--node_modules/
--@app/
|--client/
|--package.json
|--node_modules/
|--server/
|--package.json
|--node_modules/
|--db/
|--package.json
|--node_modules/
Where client/ is a React-Native app. I am aware of the gotchas in react-native, and have modified my root /package.json
as follows:
"workspaces": {
"packages": [
"@app/*"
],
"nohoist": [
"**/react-native",
"**/react-native/**",
]
},
As I understand it, this should prevent react native itself, plus any of react-native's dependencies from being hoisted. However, what I am experiencing is that react-native libraries like react-native-linear-gradient
and react-native-reanimated
(which exist solely in client/package.json
) are being hoisted and installed at the root level node_modules
. It is not even just native modules that are hoisted. Javascript dependencies are also being hoisted:
- native-base
- react-redux
- @apollo
- styled-components
Of course, the nohoist
option should not even come into play here, since these modules are only ever used within the client/
directory.
So then why would they be hoisted to the root?
For good measure, I have deleted the yarn.lock
files in each of my workspaces, keeping only the root level one. After running lerna clean
and rm -rf node_modules
, I have run yarn install
at the root level.
Interestingly, this install is very long (3-5 min). It even takes around 20s just to remove the root level node_modules
. I'm not at all sure if this is normal with yarn workspaces+lerna.
Additional Details
yarn version - 1.22.10