yarn.lock只对包管理器Yarn有用?

一、问题描述

有一个旧项目(原本可能是用yarn进行管理),而当前使用npm进行构建时虽然构建成功,但实际在客户端访问却报错。为了排查问题,首先进行以下操作:

删除node_modules、dist目录
删除package-lock.json及yarn.lock文件
执行npm cache clean --force清除npm缓存

在运行npm install后,执行npm run build时报错:

[vite-plugin-eslint] Failed to load parser 'vue-eslint-parser' declared in '.eslintrc.js': Cannot find module 'vue-eslint-parser'

在这里插入图片描述
经过确认,在项目package.json中确实没有明确安装vue-eslint-parser依赖,但在另一个小伙伴电脑上却能正常构建。

二、问题排查

首先,我们统一了本地开发的相关环境:

node: v16.8.0
npm: 7.21.0
npm config list:
; “user” config from C:\Users\xxx.npmrc
registry = “https://registry.npmmirror.com/”

然后,我们发现构建出来的package-lock.json是不同的:

在这里插入图片描述

经过对比确认,是因为小伙伴的项目中存在yarn.lock文件导致的:

在这里插入图片描述
这也就是小伙伴本地开发环境不报错的原因。

后面在npm 7相关文档中也发现了:

In prior versions, the yarn.lock files were ignored, the npm CLI can now use yarn.lock as the source of package metadata and resolution guidance. If a yarn.lock file is present, then npm will also keep it up-to-date with the contents of the package tree.

也就是,在 npm v7 中,npm 已经开始支持使用 yarn.lock 文件来管理依赖。这意味着如果项目中存在 yarn.lock 文件,npm 会优先使用该文件来安装依赖,而不是根据 package.json 文件来安装。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

晓风伴月

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

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

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

打赏作者

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

抵扣说明:

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

余额充值