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 a Nerd Font on Warp

I started using Vim as my IDE of choice recently, and one of the things I wanted early on was a more visually appealing icon and font set. I kept reading about Nerd Fonts so I decided to try installing one, but the instructions for doing so were both clear

Members Public

How to change the version of an npm package associated with a specific tag

If publishing experimental npm packages is a somewhat regular part of your development workflow, you've likely experienced some nerves around publishing that package incorrectly such that it becomes the version that anyone newly installing or upgrading the package gets. If you find that you accidentally did exactly this

How to change the version of an npm package associated with a specific tag
Members Public

How to search and filter issues and pull requests in Github by author

If you ever find yourself needing to find issues or pull requests created by someone (or a few someones) in Github, here are a few quick tips for how to do that. First up - when you're looking for an individual, you'll want to use the

How to search and filter issues and pull requests in Github by author