如何不破坏性更新npm包 ?

如何不破坏性更新npm包呢?现在npm install总是一堆警告

npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated runjs@4.4.2: This project has been renamed to 'tasksfile'. Install using 'npm install tasksfile' instead.
npm WARN deprecated @hapi/hoek@8.5.1: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated @hapi/joi@15.1.1: Switch to 'npm install joi'
npm WARN deprecated svgo@1.3.2: This SVGO version is no longer supported. Upgrade to v2.x.x.
npm WARN deprecated highlight.js@9.18.5: Support has ended for 9.x series. Upgrade to @latest
阅读 2.4k
1 个回答

这个是告诉你这些包已经有断层更新了呀。让你去阅读依赖项的更新内容,然后去修改项目内的代码。防止因为一些断层更新导致某些API不能使用了。

比如说你在 npm i 之后控制台输出的告警信息,稍微翻译一下你就明白了。

npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
# [弃用警告] request@2.88.2: request 已经弃用,具体查看 https://github.com/request/request/issues/3142

npm WARN deprecated runjs@4.4.2: This project has been renamed to 'tasksfile'. Install using 'npm install tasksfile' instead.
# [弃用警告] runjs@4.4.2: 该项目已经重命名为 'tasksfile'。使用 'npm Install tasksfile' 重新安装

npm WARN deprecated @hapi/hoek@8.5.1: This version has been deprecated and is no longer supported or maintained
# [弃用警告] @hapi/hoek@8.5.1: 该版本已被放弃,不再获得支持或维护

npm WARN deprecated @hapi/joi@15.1.1: Switch to 'npm install joi'
# [弃用警告]  @hapi/joi@15.1.1: 该项目已经切换到 `npm install joi`

npm WARN deprecated svgo@1.3.2: This SVGO version is no longer supported. Upgrade to v2.x.x.
# [弃用警告] svgo@1.3.2: 该 SVGO 版本已经不在获得支持,升级到 2.x.x 版本

npm WARN deprecated highlight.js@9.18.5: Support has ended for 9.x series. Upgrade to @latest
# [弃用警告] highlight.js@9.18.5: 9.x版本已经停止维护,升级到 @latest(最新版本)

如果你只是不想更新依赖,可以考虑使用 npm ci 来安装依赖,而不是使用 npm i
npm ci 会按照 package.jsonpackage-lock.json 中的版本来安装依赖,而是用 npm i 的话,会按照 package.json 中的版本限制规则来最新的依赖,并且更新 package.jsonpackage-log.json。规则可以查看这个问答 👉 npm的lock机制解析

一般来说我们会在开发环境使用 npm i 来跟新版本,更新一些在依赖项版本更新中修复的BUG,而在生产环境使用 npm ci 来确保和开发环境保持一致的依赖版本。

npm-install | npm Docs
npm-ci | npm Docs

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏