NPM Shrinkwrap and TeamCity Build Fails

I’ll start by pointing out that I picked the title that was most similar to the search terms I used when trying to find out what was going on with my builds the other day! I couldn’t find any information to explain what I was seeing so here’s what I figured out…

What did you do!?!

I ran npm shrinkwrap which, in basic terms, file called npm-shrinkwrap.json and lists out exact versions and locations for your dependencies and their subdependencies. There are pros and cons to this solution, but it was enough to satisfy members of the team that had concerns.

Until TeamCity started failing on every branch…

Why?

  1. My NPM shrinkwrap change was sitting in a branch waiting for QA to run all their tests against the branch.
  2. TeamCity had picked up this branch, checked it out, and gone through it’s steps.
  3. We don’t clear out the directory on each checkout as it massively increases our build times.
  4. Not clearing the directory left us with a npm-shrinkwrap.json file. All of the other branches didn’t have this file, so while TeamCity was checking out their packages.json file, it was not touching the shrinkwrapped verson.
  5. When npm install was run as part of the build process on these branches, it was using the other branch’s shrinkwrap file.
  6. FAIL.

Never fear…

Hopefully anyone googling for what is going on I will have saved you a little bit of time.