yarn import 使用package-lock.json

本文介绍如何通过 Yarn 1.7 版本支持 npm 的 package-lock.json 文件,包括环境准备、安装更新 Yarn、npm 项目初始化以及使用 yarn import 命令集成 package-lock.json 和生成 yarn.lock 文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

yarn 1.7(目前最新的版本)支持npm 的package-lock.json 了

环境准备

  • 安装更新yarn
sudo npm install -g yarn
  • 查看版本
yarn version

npm基本项目初始化

  • npm 项目初始化
npm install -y 
npm install shortid --save
  • 生成的项目结构
node_modules      package-lock.json package.json

yarn 使用package-lock.

yarn import 命令使用

  • 集成使用

生成yarn.lock

yarn  import 
  • 效果
node_modules      package-lock.json package.json      yarn.lock

参考资料

https://yarnpkg.com/blog/2018/06/04/yarn-import-package-lock/?utm_source=tuicool&utm_medium=referral

 
 
 
 
PS C:\Users\周杨\Desktop\项目源码\BookManagerVue> yarn yarn install v1.22.22 info No lockfile found. warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json. [1/5] Validating package.json... [2/5] Resolving packages... error Error: certificate has expired at TLSSocket.onConnectSecure (node:_tls_wrap:1679:34) at TLSSocket.emit (node:events:518:28) at TLSSocket._finishInit (node:_tls_wrap:1078:8) at ssl.onhandshakedone (node:_tls_wrap:864:12) info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command. PS C:\Users\周杨\Desktop\项目源码\BookManagerVue> yarn install -g yarn@latest yarn install v1.22.22 info No lockfile found. error `--global` has been deprecated. Please run "yarn global add yarn@latest" instead. info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command. PS C:\Users\周杨\Desktop\项目源码\BookManagerVue> nvm install --lts nvm : 无法将“nvm”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请 确保路径正确,然后再试一次。 所在位置 行:1 字符: 1 + nvm install --lts + ~~~ + CategoryInfo : ObjectNotFound: (nvm:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException PS C:\Users\周杨\Desktop\项目源码\BookManagerVue> yarn yarn install v1.22.22 info No lockfile found. warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json. [1/5] Validating package.json... [2/5] Resolving packages... error Error: certificate has expired at TLSSocket.onConnectSecure (node:_tls_wrap:1679:34) at TLSSocket.emit (node:events:518:28) at TLSSocket._finishInit (node:_tls_wrap:1078:8) at ssl.onhandshakedone (node:_tls_wrap:864:12) info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command. PS C:\Users\周杨\Desktop\项目源码\BookManagerVue> Get-Date 2025年6月22日 21:45:51 PS C:\Users\周杨\Desktop\项目源码\BookManagerVue> yarn cache clean yarn cache v1.22.22 success Cleared cache. Done in 0.46s. PS C:\Users\周杨\Desktop\项目源码\BookManagerVue> rm -rf node_modules Remove-Item : 找不到与参数名称“rf”匹配的参数。 所在位置 行:1 字符: 4 + rm -rf node_modules + ~~~ + CategoryInfo : InvalidArgument: (:) [Remove-Item],ParameterBindingException + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand PS C:\Users\周杨\Desktop\项目源码\BookManagerVue> yarn install --force yarn install v1.22.22 info No lockfile found. warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json. [1/5] Validating package.json... [2/5] Resolving packages... error Error: certificate has expired at TLSSocket.onConnectSecure (node:_tls_wrap:1679:34) at TLSSocket.emit (node:events:518:28) at TLSSocket._finishInit (node:_tls_wrap:1078:8) at ssl.onhandshakedone (node:_tls_wrap:864:12) info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command. PS C:\Users\周杨\Desktop\项目源码\BookManagerVue> NODE_TLS_REJECT_UNAUTHORIZED=0 yarn install NODE_TLS_REJECT_UNAUTHORIZED=0 : 无法将“NODE_TLS_REJECT_UNAUTHORIZED=0”项识别为 cmdlet、函数、脚本文件 或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。 所在位置 行:1 字符: 1 + NODE_TLS_REJECT_UNAUTHORIZED=0 yarn install + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (NODE_TLS_REJECT_UNAUTHORIZED=0:String) [], CommandNotFou ndException + FullyQualifiedErrorId : CommandNotFoundException PS C:\Users\周杨\Desktop\项目源码\BookManagerVue> certmgr.msc PS C:\Users\周杨\Desktop\项目源码\BookManagerVue> rm package-lock.json PS C:\Users\周杨\Desktop\项目源码\BookManagerVue> yarn import yarn import v1.22.22 info creating yarn.lock from local node_modules folder error "axios" not installed error "core-js" not installed error "element-ui" not installed error "file-saver" not installed error "js-cookie" not installed error "normalize.css" not installed error "nprogress" not installed error "path-to-regexp" not installed error "vue" not installed error "vue-router" not installed error "vuex" not installed error "xlsx" not installed error "@vue/cli-plugin-babel" not installed error "@vue/cli-plugin-eslint" not installed error "@vue/cli-plugin-unit-jest" not installed error "@vue/cli-service" not installed error "@vue/test-utils" not installed error "autoprefixer" not installed error "babel-eslint" not installed error "babel-jest" not installed error "babel-plugin-dynamic-import-node" not installed error "chalk" not installed error "connect" not installed error "eslint" not installed error "eslint-plugin-vue" not installed error "html-webpack-plugin" not installed error "mockjs" not installed error "runjs" not installed error "sass" not installed error "sass-loader" not installed error "script-ext-html-webpack-plugin" not installed error "serve-static" not installed error "svg-sprite-loader" not installed error "svgo" not installed error "vue-template-compiler" not installed error Found 35 errors. info Visit https://yarnpkg.com/en/docs/cli/import for documentation about this command. PS C:\Users\周杨\Desktop\项目源码\BookManagerVue> yarn install --check-files yarn install v1.22.22 info No lockfile found. [1/5] Validating package.json... [2/5] Resolving packages... error Error: certificate has expired at TLSSocket.onConnectSecure (node:_tls_wrap:1679:34) at TLSSocket.emit (node:events:518:28) at TLSSocket._finishInit (node:_tls_wrap:1078:8) at ssl.onhandshakedone (node:_tls_wrap:864:12) info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command. PS C:\Users\周杨\Desktop\项目源码\BookManagerVue>
最新发布
06-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值