Yarn - Command yarn import error: This package doesn't seem to be present in your lockfile; try to make an install to update your resolutions

Yarn - Command yarn import error: This package doesn't seem to be present in your lockfile; try to make an install to update your resolutions

我正在寻找在我的项目中同时使用 yarn 和 npm,如果我发现 yarn 对我的特定情况有用,我可以将我的项目移动到仅使用 yarn

然而,$yarn import 出现以下错误:

local:project_middleware jgil$ yarn import

Internal Error: project-middleware@workspace:.: This package doesn't seem to be present in your lockfile; try to make an install to update your resolutions
at J.getCandidates (/Users/jgil/Development/BerserkerStudio/project_middleware/.yarn/releases/yarn-berry.cjs:2:325115)
at i.getCandidates (/Users/jgil/Development/BerserkerStudio/project_middleware/.yarn/releases/yarn-berry.cjs:2:314232)
at /Users/jgil/Development/BerserkerStudio/project_middleware/.yarn/releases/yarn-berry.cjs:2:335605
at Array.map (<anonymous>)
at Ae.resolveEverything (/Users/jgil/Development/BerserkerStudio/project_middleware/.yarn/releases/yarn-berry.cjs:2:335321)
at async Ae.applyLightResolution (/Users/jgil/Development/BerserkerStudio/project_middleware/.yarn/releases/yarn-berry.cjs:2:357937)
at async Ae.restoreInstallState (/Users/jgil/Development/BerserkerStudio/project_middleware/.yarn/releases/yarn-berry.cjs:2:357667)
at async Ke.execute (/Users/jgil/Development/BerserkerStudio/project_middleware/.yarn/releases/yarn-berry.cjs:2:98394)
at async Ke.validateAndExecute (/Users/jgil/Development/BerserkerStudio/project_middleware/.yarn/releases/yarn-berry.cjs:2:626801)
at async j.run (/Users/jgil/Development/BerserkerStudio/project_middleware/.yarn/releases/yarn-berry.cjs:17:3854)

我已经 运行 $yarn set version berry 并一次又一次地尝试删除 node_modules 目录、运行ning npm install 等不同组合. 没有任何东西可以使它工作...不知道缺少什么。

会不会是 Node.js 的版本或我正在使用的任何其他组件的问题?

此处的问题似乎是其中一个工作区内现有的 yarn.lock 文件。删除它解决了问题。

更多信息:

示例:3 个工作区:2 个 create-react-app (app, home) 和一个共享组件:(components)

component 文件夹中存在一个挥之不去的 yarn.lock 文件。删除它。

同时检查:

  1. 您所有的工作区在其每个 package.json 中都有 "private": true(与 nameprivatesource 相同级别)。
  2. 检查您是否已将工作区添加到主 package.json
  3. 中的 "workspaces" 键中
  4. 当您执行 yarn workspaces myworkspace 时,myworkspace 与您在 package.json 中的工作区名称相匹配。在我的例子中,components 文件夹内的工作区名称称为 @schon/components,因此我需要将其命名为 yarn worksapces @schon/components

同样的错误出现在我身上,我发现我错误地添加了.yarnrc.yml。在 yarn-berry.cjs 中删除文件及其引用后,我得到了解决方案和项目 运行