解决 npm upgrade 或者 yarn upgrade时 package.json 依赖未更新

在项目开发中,随着项目迭代,我们需要更新我们的项目包,但是有心的同学就会发现,在更新包的时候仅仅使用 yarn upgrade 或者 npm upgrade 时,只有 yarn.lock 文件或者 package-lock.json 文件更新,而我们的包文件 package.json 却没有表示出新的包版本,那么我们如何解决呢?

  1. 输入更新的命令
    注意这里的更新命令不是 upgrade 哦,而是使用 upgrade-interactive 命令,我们看看这个命令有何神奇之处

    使用 yarn help upgrade-interactive 查看帮助信息

    Usage: yarn upgrade-interactive [flags]
    
      Provides an easy way to update outdated packages.
    
      Options:
    
        -v, --version                       output the version number
        --no-default-rc                     prevent Yarn from automatically detecting yarnrc and npmrc files
        --use-yarnrc <path>                 specifies a yarnrc file that Yarn should use (.yarnrc only, not .npmrc) (default: )
        --verbose                           output verbose messages on internal operations
        --offline                           trigger an error if any required dependencies are not available in local cache
        --prefer-offline                    use network only if dependencies are not available in local cache
        --enable-pnp, --pnp                 enable the Plug'n'Play installation
        --disable-pnp                       disable the Plug'n'Play installation
        --strict-semver
        --json                              format Yarn log messages as lines of JSON (see jsonlines.org)
        --ignore-scripts                    don't run lifecycle scripts
        --har                               save HAR output of network traffic
        --ignore-platform                   ignore platform checks
        --ignore-engines                    ignore engines check
        --ignore-optional                   ignore optional dependencies
        --force                             install and build packages even if they were built before, overwrite lockfile
        --skip-integrity-check              run install without checking if node_modules is installed
        --check-files                       install will verify file tree of packages for consistency
        --no-bin-links                      don't generate bin links when setting up packages
        --flat                              only allow one version of a package
        --prod, --production [prod]
        --no-lockfile                       don't read or generate a lockfile
        --pure-lockfile                     don't generate a lockfile
        --frozen-lockfile                   don't generate a lockfile and fail if an update is needed
        --update-checksums                  update package checksums from current repository
        --link-duplicates                   create hardlinks to the repeated modules in node_modules
        --link-folder <path>                specify a custom folder to store global links
        --global-folder <path>              specify a custom folder to store global packages
        --modules-folder <path>             rather than installing modules into the node_modules folder relative to the cwd, output them here
        --preferred-cache-folder <path>     specify a custom folder to store the yarn cache if possible
        --cache-folder <path>               specify a custom folder that must be used to store the yarn cache
        --mutex <type>[:specifier]          use a mutex to ensure only one yarn instance is executing
        --emoji [bool]                      enable emoji in output (default: true)
        -s, --silent                        skip Yarn console logs, other types of logs (script output) will be printed
        --cwd <cwd>                         working directory to use (default: /Users/mengjun/Documents/repository/start)
        --proxy <host>
        --https-proxy <host>
        --registry <url>                    override configuration registry
        --no-progress                       disable progress bar
        --network-concurrency <number>      maximum number of concurrent network requests
        --network-timeout <milliseconds>    TCP timeout for network requests
        --non-interactive                   do not show interactive prompts
        --scripts-prepend-node-path [bool]  prepend the node executable dir to the PATH in scripts
        --no-node-version-check             do not warn when using a potentially unsupported Node version
        --focus                             Focus on a single workspace by installing remote copies of its sibling workspaces.
        --otp <otpcode>                     one-time password for two factor authentication
        -S, --scope <scope>                 upgrade packages under the specified scope
        --latest                            list the latest version of packages, ignoring version ranges in package.json
        -E, --exact                         install exact version. Only used when --latest is specified.
        -T, --tilde                         install most recent release with the same minor version. Only used when --latest is specified.
        -C, --caret                         install most recent release with the same major version. Only used when --latest is specified.
        -h, --help                          output usage information
      Visit https://yarnpkg.com/en/docs/cli/upgrade-interactive for documentation about this command.
    
  2. 简单的使用 --latest 代表将安装包更新到最新版本

    yarn upgrade-interactive --latest
    
  3. 然后就可以看到可更新的安装包列表,此时我们输入 a 代表全选,然后回车即可;或者我们使用空格键选择想要更新的包,然后回车。

  4. 到这里就大功告成了,快看一看你的 package.json 是否已经同步更新了

更多内容

前端开发转全栈,目前的技术栈是 Node.js、Python,日常研究 C、C++ 和 Rust,孜孜啃食系统开发和网络设计中~

更多的内容请移步GitHub@ruxf,知乎@如小非,掘金@如小非,或者关注我的公众号@全栈开发师,欢迎来撩~

学到老,写到老,生命不停,编程不止~

加油,打工人~

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

mrmengj

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值