I just recently successfully changed to using yarn on one of my systems, replacing npm, for my react-native projects. used yarn version 1.22.11.I ran it and it resolved dependencies beautifully and there were no problems.
So I copied the project over to another computer. I wanted to do the same thing -- use yarn with it-- but when I run the 'yarn' command, instead of going through my directory and fixing my dependencies...
...yarn goes through my directory and deletes not only the files, but the folders!! This is yarn version 2.4.1.
Anyone have thoughts about why this might happen?
yarn 2 does not use or create node_modules directory by default, instead it uses a new technology called plug 'n play (pnp). If you upgrade to yarn 2.x from yarn 1.x it will delete the node_modules folder.
For a primer on yarn 2 and pnp, see https://dev.to/arcanis/introducing-yarn-2-4eh1 and https://yarnpkg.com/features/pnp
If you want to turn off pnp in yarn 2 and use node_modules, see: How to turn off yarn@2 PnP?
But most of the community has stuck with yarn 1.x. See https://blog.hao.dev/state-of-yarn-2-berry-in-2021
You may decide to stick with yarn 1.x, return to npm, or try yarn 2.x berry with or without pnp. In general, if your project can work with pnp, it is much faster. However, many packages in the javascript ecosystem are incompatible.
Update 2022: Yarn 3.x is now available, and is easier to update to than yarn 2. pnpm is now also an interesting choice.
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