If you face any issue something like this in your local terminal or in any of your task runners like Github Actions or Travis, You can solve them by using any one of the following possible solutions.
This is one of the common issues occur in yarn
package manager.
Integrity checksums are a security feature used by Yarn to ensure
that the contents of a package have not been tampered with since they
were published to the registry. So, when you install a package, Yarn
downloads the package's tarball from the registry and verifies that
the integrity checksum matches the one listed in the
yarn.lock
file.
-
Source
Solutions
There's no single answer for this. Because there are different scenarios for different code base in which this error occurs. So I tried my best to list all possible answers that I learned fixing this issue.
Solution 1: Clearing cache
yarn cache clean
In some blogs they say this as one of the solution, but it never worked for me. You can give it a try. No hard in trying π
Solution 2: Update Checksums
-
Use
yarn --update-checksums
oryarn install --update-checksums
-
If thereβs a change in the
yarn.lock
file in thatpackage-name
's keys such asintegrity
andresolved
then the solution is resolved. (Wherepackage-name
refers to the package name where it threw error Integrity check failed forpackage-name
)
If the current solution is not working then
Solution 3: Reinstall that particular package
If that particular package is part of the package.json
's
dependencies
(Or devDependencies
), then
yarn remove <package-name>
yarn add <package-name> --update-checksums
Use --save-dev
at the last if it's a dev dependency.
If the particular package is part of your dependencies in
package.json
and still it is not fixed then you can directly go
to solution 4.
If that particular package is not part of the
package.json
's dependencies
(Or
devDependencies
), then it is a child dependency of any of the
package that you used. So find the parent package for that and reinstall using
the same commands mentioned above.
To find the parent package
- Open
yarn.lock
file. - Search for the package name.
-
Find an occurrence where it will be under
dependencies
of another package.
This is how the structure of yarn.lock
looks like for a package
-
If that package name is part of your dependencies in
package.json
then run the scripts mentioned above (Under Solution 3) else recursively run the step 3 until you reach a package name where it is available as a dependency inpackage.json
If the current solution is not working then
Solution 4: Remove yarn.lock
and do yarn install
This is the last and the brutal solution for this case, where in most case, it just works.
- Remove
yarn.lock
- Do
yarn install
Mostly it should work. Else you can remove both yarn.lock
and
node_modules
folder and try again.
This should do.
If there are any more edge cases with any different solutions please do add them as comments or let me know. Thanks π