integrity in yarn.lock

What the integrity field in yarn.lock means, how it’s computed, and why not every package has it.

Mar 19, 2020 · 1 min read · 120 Words · -Views -Comments · Programming
Node.js Frontend Development
Read with AI

Choose an AI assistant

ChatGPT Open in a new tab with the article link and prompt
Claude Copy the prompt, then open Claude

Open Claude
Trouble reading the article?

If the prompt is missing, copy the full prompt below into your AI assistant. If the AI cannot read the article, paste the visible passage you want to discuss and add your question.

When committing code you may notice diffs in yarn.lock adding or removing integrity fields. Here’s a quick rundown of what it is.

Purpose

Ensures resource integrity (package version and content). After Yarn downloads a resource, it compares the computed integrity to the one in the file; if they don’t match, installation fails.

How is integrity computed?

Typically: hash(bytes) → base64‑encode.

Why isn’t it on every package?

In theory, it should be present for every package.

v1.9.4

Reproduced at the time: delete lockfile, run yarn install, some packages still lacked integrity.

v1.22.4

After upgrading, retrying showed every package had integrity.

Conclusion

A version bug — upgrading resolves it.

References

Authors
Developer, digital product enthusiast, tinkerer, sharer, open source lover