bug^君 2014-03-12 06:02 采纳率: 25%
浏览 468
已采纳

Package.json 中的 tilde (~)和 caret (^)有什么区别?

After I upgraded to latest stable node and npm, I tried npm install moment --save. It saves the entry in the package.json with the caret(^) prefix. Previously, it was a tilde(~) prefix.

  1. Why are these changes made in npm?
  2. What is the difference between tilde(~) and caret(^)?
  3. What is the advantages over others?

转载于:https://stackoverflow.com/questions/22343224/whats-the-difference-between-tilde-and-caret-in-package-json

  • 写回答

14条回答 默认 最新

  • ℙℕℤℝ 2014-03-12 08:28
    关注

    In the simplest terms, the tilde matches the most recent minor version (the middle number). ~1.2.3 will match all 1.2.x versions but will miss 1.3.0.

    The caret, on the other hand, is more relaxed. It will update you to the most recent major version (the first number). ^1.2.3 will match any 1.x.x release including 1.3.0, but will hold off on 2.0.0.

    http://fredkschott.com/post/2014/02/npm-no-longer-defaults-to-tildes/

    Note that the author's terminology is somewhat misleading: when he says "the most recent minor version" for ~ he means "the most recent patch version in the specified minor version". Similarly for ^, "the most recent major version" should be read as "the most recent minor version in the specified major version".

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(13条)

报告相同问题?

悬赏问题

  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥200 关于#c++#的问题,请各位专家解答!网站的邀请码
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号