Testcafe 不会 运行 使用 Yarn 2

Testcafe won’t run with Yarn 2

Testcafe 1.10 似乎没有通过 Yarn 2 运行,而它只是 运行 手动安装全局安装的。我得到这个输出:

ERROR Error: testcafe-legacy-api tried to access read-file-relative, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

Required package: read-file-relative (via "read-file-relative")
Required by: testcafe-legacy-api@npm:4.0.0 (via /data/Fichiers/Code/testcafe/.yarn/cache/testcafe-legacy-api-npm-4.0.0-ff97b69c8c-e4a891ec41.zip/node_modules/testcafe-legacy-api/lib/)

我可以看到 read-file-relative 列为 testcafe 的依赖项,但 不是 testcafe-legacy-api (https://yarnpkg.com/package/testcafe, https://yarnpkg.com/package/testcafe-legacy-api) 的依赖项,它本身是 testcafe.

的依赖项

编辑:双方的 PR 已合并,因此它现在或不久应该可以工作,而无需使用下面的解决方法。

显然 testcafe 及其依赖项 testcafe-legacy-api 有几个未在其依赖项列表中列出的实际依赖项。

正如 documentation for .yarnrc.yml 解释的那样:

Some packages may have been specified incorrectly with regard to their dependencies - for example with one dependency being missing, causing Yarn to refuse it the access. The packageExtensions fields offer a way to extend the existing package definitions with additional information.

将此添加到我的 .yarnrc.yml,然后 运行 yarn install(或 yarn)修复了它:

packageExtensions:
  "testcafe@*":
    dependencies:
      "@babel/runtime": "*"
      "@babel/plugin-transform-for-of": "*"
  "testcafe-legacy-api@*":
    dependencies:
      "read-file-relative": "*"
      "testcafe-hammerhead": "*"