npm 中文文档 npm 中文文档
指南
npmjs.com (opens new window)
指南
npmjs.com (opens new window)
  • 快速入门

    • npm 是什么?
    • npm 安装和更新
    • npm 防止权限错误
    • npm package.json 文件
    • npm 安装包
    • npm 更新包
    • npm 卸载包
    • npm 创建 Node.js 模块
    • npm 发布和更新包
    • npm 使用语义化版本
    • npm 使用 Dist-tags 标记包
    • npm 包和模块的了解
  • 命令行
  • 配置 npm

NPM Force Resolutions


This packages modifies package-lock.json to force the installation of specific version of a transitive dependency (dependency of dependency), similar to yarn's selective dependency resolutions, but without having to migrate to yarn.

WARNING before you start


The use case for this is when there is a security vulnerability and you MUST update a nested dependency otherwise your project would be vulnerable. But this should only be used as a last resource, you should first update your top-level dependencies and file an issue for them to update the vulnerable sub-dependencies (npm ls <vulnerable dependency> can help you with that).

How to use


First add a field resolutions with the dependency version you want to fix to your package.json, for example:

  1. ``` json
  2. "resolutions": {
  3.   "hoek": "4.2.1"
  4. }
  5. ```

Then add npm-force-resolutions to the preinstall script so that it patches the package-lock file before every npm install you run:

  1. ``` json
  2. "scripts": {
  3.   "preinstall": "npx npm-force-resolutions"
  4. }
  5. ```

Now just run npm install as you would normally do:

  1. ``` sh
  2. npm install

  3. ```

To confirm that the right version was installed, use:

  1. ``` sh
  2. npm ls hoek

  3. ```

If your package-lock changes, you may need to run the steps above again.

Contributing


To build the project from source you'll need to install clojure. Then you can run:

  1. ``` sh
  2. npm install
  3. npm run build

  4. ```
Last Updated: 2023-05-15 10:22:02