Skip to main content
View on YouTube to comment and like!

Syntax Video

don't gitignore your lock files!

Chapter 1 00:00

Transcript

why would I use a lock file for managing my dependencies rather than just pinning the exact versions in my package Json seems like those actions do the exact same thing except the lock file is a billion times longer and not human readable IMO pin your dependency versions and run npm audit often that's not a good idea and I'm going to explain to you why in order to understand why just pinning your dependency which means just removing the Tilda we need to understand how sver Works in package Json so sver refers to to software versioning semantic versioning where you have three numbers the first one being a major the second one being a minor and the third one being a patch major is a breaking change you've changed the API things will break if you upgrade minor is oh yeah you you've updated you've added some features but you've not changed how the API works you simply just add a feature and then patches is like bug fixes you know so when you npm install something you by default it gives you this little carrot here and

what that carrot is going to tell you is I will take any 4 point whatever version meaning that um the both the minor version and the patch version can be upgraded so this could give me 4.2.0 but if the developer behind this package has has renewed a new one and they put out a 4.2.1 I'm going to get that version but also if they said ah I'm going to add a new feature and they are going to then release a 4 .

3.1 you're you're going to get the latest version with the carrot there now with the Tilda it's the same idea but you're only ever going to accept patches not M minor version updates so you could get 4.2.7 but you would not get 4.3.0 until you explicitly go ahead and upgrade your package Json so that's how semantic versioning works now if you went into your package Json like the question has asked us and simply just remove that that's referred to as pinning your dependencies meaning that I need the dependency of 6.0.2 until I explicitly go and upgrade it myself never ever will you give me 6.0.3 so that's good the problem lies in that their dependencies have dependencies and those dependencies have dependencies and the dependency tree goes all the way down so if you take a

look at this website mpm graph and you take a look at something like like Tailwind CSS Tailwind CSS has 3.4.7 so if I pinned to that specific version it's going to always install that Tailwind CSS version but tailwins package Json if you take a look at their dependencies they are using the the carrot there meaning that their dependencies are not explicitly pinned to that version and if you look all the way down their dependencies are are are not necessarily pinned and theirs are not necessarily pinned and all the way down um and that that's a good thing because if there's a minor version fix in one of these things that are eight levels deep you don't have to go chasing all the way up the tree making sure that every single dependency updates itself so if this dependency right here has a little bug and it fixes itself if there is carrots or tildas in the package Json all the way up the tree then it will

just sort of propagate the next time you do a npm install now that's great but that can also lead to actual issues because what happens is you you install locally you run everything you run your tests and everything works and then you go ahead and deploy to your production and in the time that that has happened one of your dependencies or one of your dependency dependencies has had a minor or uh patch update to it and you're going to get that version and there you go the code that you have been developing against and the code that you have been testing against is no longer the exact same code that you are now pushing into production and that's a little bit scary both from the reliability point of view but also from a security point of view where one of these dependencies eight levels deep to slip the little Bitcoin minor or a back door into their package then you're going to be in a little bit of trouble so don't get ignore your package lock file it is really annoying when you get

get conflicts in there and often what you'll have to do is just go ahead and nuke it npm install commit the package Json or do the merge manually and then push it on up always keep it in there it's going to give you much more peace of mind

Quote it with credit and a link. Quoting Syntax