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-checksumsoryarn install --update-checksums -
If thereβs a change in the
yarn.lockfile in thatpackage-name's keys such asintegrityandresolvedthen the solution is resolved. (Wherepackage-namerefers 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.lockfile. - Search for the package name.
-
Find an occurrence where it will be under
dependenciesof another package.
This is how the structure of yarn.lock looks like for a package
<parent-package-name>@<version>":
version "<version>"
resolved "<link>"
integrity <integrity-hash>
dependencies:
"<package-name-1>" "<version>"
"<package-name-2>" "<version>"
"<particular-package>" "<version>"
next@12.3.0:
version "12.3.0"
resolved "https://nexus.hackerrank.com/repository/hr-npm-group/next/-/next-12.3.0.tgz#0e4c1ed0092544c7e8f4c998ca57cf6529e286cb"
integrity sha512-GpzI6me9V1+XYtfK0Ae9WD0mKqHyzQlGq1xH1rzNIYMASo4Tkl4rTe9jSqtBpXFhOS33KohXs9ZY38Akkhdciw==
dependencies:
"@next/env" "12.3.0"
"@swc/helpers" "0.4.11"
caniuse-lite "^1.0.30001332"
postcss "8.4.14"
styled-jsx "5.0.6"
use-sync-external-store "1.2.0"
@swc/helpers then reinstall next@12.3.0
-
If that package name is part of your dependencies in
package.jsonthen 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 π
