Skip to content

Bug in dependency or module resolution issues? Debugging with Selective Dependency Resolutions

Erica Pisani
Erica Pisani
1 min read

When multiple versions of a dependency are used in your Node project and you start seeing build or import errors related to that dependency, it can be frustrating to solve.

I recently learned about selective dependency resolutions (SDR) and it has since made me more confident in debugging these types of errors. SDR makes it easier to rule out if the error(s) I'm seeing are due to a newer version of a dependency (maybe a bug or a change in API in that version?) or if there's an issue with module resolution in my project.

How do I use it?

By adding a resolutions object in your package.json, you can specify the version of a dependency to be used by all consumers of that package in the project. This includes uses of that dependency within other dependencies.

{
	"resolutions": {
	    // This pins all uses of 'some-dependency' to '1.0.0'
        // instead of what's listed in the 'dependencies' or 
        // 'devDependencies' sections
    	"some-dependency": "1.0.0",
        "another-dependency": ">=1.0.0 || 2.0.0"
    }
}

Which package managers have this?

Yarn and pnpm both have support for the resolutions field, and npm achieves this through the overrides field.

Additional resources

If you'd like to read more about this, Yarn's documentation is great. They have a formal specification of the feature as well since I believe they were the first package manager to add this feature.


📫
Enjoy this post? Subscribe to be notified when I publish new content!
tips-and-tricksnodejs

Comments


Related Posts

Members Public

How to install nvim-ufo in LazyVim to enable foldable code blocks

A feature that I've found myself missing since making the switch to Vim as my editor of choice is the ability to easily fold and expand code blocks. I know this functionality is included in Neovim, but I couldn't understand the native implementation enough to use

How to install nvim-ufo in LazyVim to enable foldable code blocks
Members Public

Git Log's Hidden Gems: Using -S and -L for Powerful Code History Search

Ever needed to track down when a specific piece of code was first introduced in a project? As part of some refactoring I had to do recently, I needed to do just that for a variable on a Django model. I was already familiar with the basic git log command,

Git Log's Hidden Gems: Using -S and -L for Powerful Code History Search
Members Public

Using XOR to write concise conditionals

It's not uncommon that I sometimes write if statements where the overall conditional is true when both conditions are true or both are false. As an example, let's say I'm validating input from an API call where I'm updating information on a