Skip to content
Advertisement

How can I block or opt-out of installing a dependency with Yarn?

I’m using Gatsby, which has a long list of sub-dependencies, some of which I’d like to never allow Yarn to install and execute. Ideally I’d like to be able to add a per-project blocklist, but I’m open to other ways of achieving the same goal of not installing specific packages, even if it leads to errors in the direct dependencies that rely on them.

To be clear, I’m not looking to merely install another version of the same package, but instead to prevent it from being installed at all. If I can replace it with a package I control that is just a shim that’d be a nice solution too.

I’ve tried using resolutions with the package version set to null, but this didn’t seem to have an affect.

Advertisement

Answer

Using resolution and link as version works for me to setup webpack5 instead of webpack4 for storybook.

"resolutions": {
    "webpack": "5",
    "@storybook/builder-webpack4": "link:./node_modules/@storybook/builder-webpack5"
}

In order to completely blocks the package it’s possible to link to unexisting folder like: ./node_modules/.cache/null

https://yarnpkg.com/features/protocols

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement