<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Hamza Awais</title>
    <description>The latest articles on Forem by Hamza Awais (@hamawis).</description>
    <link>https://forem.com/hamawis</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F120182%2F172aefa5-6728-4138-9135-0d558b4e9d36.JPG</url>
      <title>Forem: Hamza Awais</title>
      <link>https://forem.com/hamawis</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/hamawis"/>
    <language>en</language>
    <item>
      <title>Your Yarn Lockfile Is Trying to Protect You — Let It</title>
      <dc:creator>Hamza Awais</dc:creator>
      <pubDate>Wed, 24 Dec 2025 14:26:11 +0000</pubDate>
      <link>https://forem.com/hamawis/your-yarn-lockfile-is-trying-to-protect-you-let-it-3hb7</link>
      <guid>https://forem.com/hamawis/your-yarn-lockfile-is-trying-to-protect-you-let-it-3hb7</guid>
      <description>&lt;p&gt;Ever had a build fail for &lt;em&gt;no obvious reason&lt;/em&gt;?&lt;/p&gt;

&lt;p&gt;No code changes.&lt;br&gt;
No dependency updates.&lt;br&gt;
Nothing that should’ve broken anything.&lt;/p&gt;

&lt;p&gt;Yet CI is red. A teammate can’t reproduce the issue. Production behaves differently from yesterday.&lt;/p&gt;

&lt;p&gt;That’s not bad luck.&lt;br&gt;&lt;br&gt;
That’s your &lt;strong&gt;lockfile being ignored&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;And the fix is simpler than you think.&lt;/p&gt;


&lt;h2&gt;
  
  
  The Lockfile Is the Real Source of Truth
&lt;/h2&gt;

&lt;p&gt;In every Yarn project, two files work together:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;package.json&lt;/code&gt; defines &lt;strong&gt;what’s allowed&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;yarn.lock&lt;/code&gt; defines &lt;strong&gt;what actually gets installed&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If Yarn is allowed to rewrite the lockfile during installation, you’re no longer guaranteed the same dependencies every time.&lt;/p&gt;

&lt;p&gt;You’re &lt;em&gt;hoping&lt;/em&gt; you are.&lt;/p&gt;

&lt;p&gt;Hope is not a build strategy.&lt;/p&gt;


&lt;h2&gt;
  
  
  What “Frozen” (or Immutable) Installs Actually Mean
&lt;/h2&gt;

&lt;p&gt;A frozen or immutable install tells Yarn:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install &lt;strong&gt;exactly&lt;/strong&gt; what’s in &lt;code&gt;yarn.lock&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;If anything doesn’t match, fail immediately.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;No silent upgrades.&lt;br&gt;
No registry surprises.&lt;br&gt;
No mysterious diffs showing up in PRs.&lt;/p&gt;

&lt;p&gt;It turns your lockfile into a &lt;strong&gt;contract&lt;/strong&gt;, not a suggestion.&lt;/p&gt;


&lt;h2&gt;
  
  
  Why This One Setting Changes Everything
&lt;/h2&gt;

&lt;p&gt;Without frozen installs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Builds change over time&lt;/li&gt;
&lt;li&gt;CI depends on timing and registry state&lt;/li&gt;
&lt;li&gt;Bugs appear without code changes&lt;/li&gt;
&lt;li&gt;Rollbacks don’t restore previous behavior&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With frozen installs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Identical installs across machines
&lt;/li&gt;
&lt;li&gt;Early, predictable CI failures
&lt;/li&gt;
&lt;li&gt;Less time debugging environments
&lt;/li&gt;
&lt;li&gt;More confidence shipping changes
&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  How to Do This with Yarn (By Version)
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Yarn v1 (Classic)
&lt;/h3&gt;

&lt;p&gt;Yarn v1 does &lt;strong&gt;not&lt;/strong&gt; freeze installs by default.&lt;/p&gt;

&lt;p&gt;You must opt in:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;yarn install --frozen-lockfile&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;This prevents Yarn from modifying &lt;code&gt;yarn.lock&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Always use this in CI.&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Yarn Berry (v2 / v3)
&lt;/h3&gt;

&lt;p&gt;Yarn Berry improves things significantly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CI environments&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When &lt;code&gt;CI=true&lt;/code&gt; (GitHub Actions, GitLab CI, CircleCI):&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;yarn install&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;That’s it.&lt;/p&gt;

&lt;p&gt;Yarn automatically enforces immutable installs.&lt;br&gt;
If &lt;code&gt;yarn.lock&lt;/code&gt; doesn’t match package.json, the build fails.&lt;/p&gt;

&lt;p&gt;No extra flags required.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Want the same strictness locally?&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;yarn install --immutable&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Now local installs behave exactly like CI.&lt;/p&gt;

&lt;h2&gt;
  
  
  When Lockfiles Should Change
&lt;/h2&gt;

&lt;p&gt;Lockfiles should change only when you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add a dependency&lt;/li&gt;
&lt;li&gt;Upgrade a package&lt;/li&gt;
&lt;li&gt;Intentionally modify versions
They should never change just because someone ran yarn install.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If they do, your process — not your code — is broken.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Hidden Benefit: Confidence
&lt;/h2&gt;

&lt;p&gt;When installs are immutable:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A green build actually means something&lt;/li&gt;
&lt;li&gt;A rollback restores behavior, not surprises&lt;/li&gt;
&lt;li&gt;Bugs come from code changes, not environment drift&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That confidence compounds across teams and deployments.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Thought
&lt;/h2&gt;

&lt;p&gt;Most “random” bugs aren’t random at all.&lt;/p&gt;

&lt;p&gt;They’re caused by installs that were too flexible and lockfiles that weren’t treated seriously.&lt;/p&gt;

&lt;p&gt;Yarn gives you the tools to lock things down — especially with Berry making immutability the default in CI.&lt;/p&gt;

&lt;p&gt;So let your lockfile do its job.&lt;/p&gt;

&lt;p&gt;Freeze it.&lt;br&gt;
Trust it.&lt;br&gt;
Ship with confidence. 🚀&lt;/p&gt;

</description>
      <category>yarn</category>
      <category>ci</category>
      <category>devops</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
