Can different yarn versions cause yarn install to modify the content of yarn.lock files? - node.js

My question is: when I run yarn install locally, it modifies the yarn.lock file I pulled from a Github source. There is nothing changed in package.json file.
My best guess is that I am using yarn 1.22.18 locally, but the latest commit of yarn.lock on Github (which I just pulled) uses 1.22.19 to generate.
Could different yarn versions cause this issue?
ps: previously, yarn.lock file on Github source was generated by yarn 1.22.17, even though I am using yarn 1.22.18. when I do yarn install, there is nothing changed in my local yarn.lock file.
I did some research on my issue, but cannot find any good articles about this problem (Why is my yarn.lock file changing when running yarn install after incrementing version in package.json?). If someone thinks this issue is a duplicate, please kindly provide a link and I will close this issue.
Thanks so much in advance!

Related

Run `yarn remove <dependency_name>` to remove dependency, but yarn.lock still shows the removed dependency

In my node.js project, I had using yarn installed the dependency #nestjs/jwt, now I want to uninstall it since I am not using it.
I run yarn remove #nestjs/jwt. It was successful. I checked my package.json, it was removed. But when I check the yarn.lock file, it is still showing. Why is that?
My git add -p yarn.lock shows me:
-"#nestjs/jwt#8.0.0", "#nestjs/jwt#^8.0.0":
+"#nestjs/jwt#^8.0.0":
version "8.0.0"
resolved "https://registry.yarnpkg.com/#nestjs/jwt/-/jwt-8.0.0.tgz#6c811c17634252dd1qcd5dabf409db4692b812da"
integrity sha512-fz2LQgYY2zmuD8S+8UE215anwKyXlnB/1FwJMLVR47clNfMeFMK8WCxmn6xd0hF5JKuV1crO6FVabb1qWzDxqQ==
Besides packages you explicitly install, packages depend on other packages. To see a graph of any dependents of this package you have installed, do:
yarn why #nestjs/jwt -R
Yarn.lock is what yarn uses to know what versions of each dependency are installed so it can get those exact versions again when you run yarn install on a new machine. Try running 'yarn upgrade'. This should create a new yarn.lock file without those dependencies.

Yarn erased my node_modules folder, every time

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.

VS Code cannot read Node Modules file when doing yarn install (it can read when doing npm install)

When ever I install my packages using Yarn, VS Code is not able to read the node_module files that are using in index.js or for that matter anywhere. However, when I do npm install, it starts working fine.
How can I fix this?
System: Mac - tried different Macs, same result.
I had a similar issue, and I had to do yarn init to get the package.json file to appear in the folder. Once I did that, adding a yarn add added the node_modules in the folder in vscode.

how to fix yarn.lock and package-lock json mix

So i was going on with my nodejs project and was trying to install a package with npm, but it got stuck in the process. I found I could use yarn which i, the very next second, did. It worked, but now im trying to host it on Heroku and I have both, package-lock.json and yarn.lock. If i delete any, the dependencies get outdated. how can i fix this?
My dependencies:
express,
passport,mongoose,ejs
I tried and searched the web for a while but nothing seemed to help me.
Just do yarn install and it will install all the dependencies again with updateing the yarn.lock. And then you can delete package-lock.json.

How to sync `yarn.lock` with `package.json`?

I installed a package with yarn add --dev, run its setup process and during it, the package installed several other packages and added those to package.json (in devDependencies), I assume with npm. Great, but now my yarn.lock is out of sync.
What is the correct, non-manual way of syncing yarn.lock to the current state of package.json?
Edit: yarn check shows the missing packages as:
error Lockfile does not contain pattern: <package>#<version>
But it doesn't add them.
Run yarn install, or just yarn.
The lock file is updated in its entirety on any change to dependencies, i.e. when you run a yarn command.
From the Yarn docs:
Your yarn.lock file is auto-generated and should be handled entirely by Yarn. As you add/upgrade/remove dependencies with the Yarn CLI, it will automatically update your yarn.lock file. Do not edit this file directly as it is easy to break something.
(Emphasis my own)
If you ever face a checksum issue this will solve it,
YARN_CHECKSUM_BEHAVIOR=update yarn

Resources