最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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.

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.

Share Improve this question asked Feb 21, 2021 at 1:28 coreywardcoreyward 80.1k21 gold badges146 silver badges175 bronze badges 5
  • Have you tried using resolutions with your custom versions of the packages and the Offline cache? – Hernán Alarcón Commented Feb 21, 2021 at 2:14
  • @HernánAlarcón Can resolutions be used to specify a custom version? Will offline cache work when deps are installed on other machines? – coreyward Commented Feb 21, 2021 at 4:48
  • The Selective dependency resolutions page literally says: "lets you define custom package versions". The Offline cache page also says: "making it suitable for being stored within a repository, as we actually do in the Yarn repository itself", so I guess it will work on different machines as long as they use the same repository. – Hernán Alarcón Commented Feb 21, 2021 at 16:34
  • Terminology seems to be getting mixed up here. I intend “custom version” to mean code that has not been released as part of the package on NPM, but it appears the Selective Dependency Resolutions docs intend it to mean a specific version that is available on NPM. It doesn't appear that offline cache is a feature of Yarn v1 (at least I couldn't find anything about it in the documentation). Yarn v2 is largely inpatible with major JS tools like React Native or Gatsby. – coreyward Commented Feb 22, 2021 at 16:39
  • Yarn classic does have a page about offline mirror: classic.yarnpkg./en/docs/offline-mirror – Hernán Alarcón Commented Feb 22, 2021 at 16:50
Add a ment  | 

1 Answer 1

Reset to default 10 +250

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 pletely blocks the package it's possible to link to unexisting folder like: ./node_modules/.cache/null

https://yarnpkg./features/protocols

发布评论

评论列表(0)

  1. 暂无评论