Using Yarn 3 aka Berry.
I'm having trouble with Yarn wanting to install multiple copies (not versions) of packages. That's trouble for me because these packages have stateful modules, so they might be initialized with some state in one copy of the package but then when I try to access those values Node reaches into the other copy of the package.
For example, imagine that package C
has some stateful module I only want one copy of.
Code for A/package.json
{
"version": "1.0.0",
"name": "A",
"dependencies": {
"C": "1.0.0"
}
}
Code for B/package.json
{
"version": "1.0.0",
"name": "B",
"dependencies": {
"C": "1.0.0"
}
}
Project package.json file
{
"version": "1.0.0",
"name": "project",
"dependencies": {
"A": "1.0.0",
"B": "1.0.0",
"C": "1.0.0"
}
}
Project's node_modules after running a yarn install
node_modules/
- A
- node_modules
- C
- package.json (v1.0.0)
- <pkg code>
- B
- node_modules
- C
- package.json (v1.0.0)
- <pkg code>
- C
- package.json (v1.0.0)
- <pkg code>
I have used yarn's resolutions
field to make sure the 'C' package has a resolution to the same version. I have tried yarn dedupe
but that only seems to affect packages of different versions.
Is there anything I can do to change the node_modules
structure to just install C
at the top level only?