Jest 在工作区中找不到模块

And*_*dry 7 npm jestjs ts-jest npm-workspaces

我有一个在工作区中构建的 NPM 项目:

proj/
+-node_modules/
+-packages/
  +-pkg1/
    +-src/
      |-c1.ts
      |-c1.test.ts
    |-package.json
    |-jest.config.js
  +-pkg2/
    +-src/
      |-c2.ts
    |-package.json
+-apps/
|-package.json
Run Code Online (Sandbox Code Playgroud)

该项目的package.json

{
  "name": "proj",
  "scripts": {
    ...
    "test:pkg1": "npm test -w packages/pkg1",
  },
  "workspaces": [
    "packages/*",
    "apps/*"
  ]
}
Run Code Online (Sandbox Code Playgroud)

里面:package.jsonpkg1

{
  "name": "@proj/pkg1",
  "scripts": {
    ...
    "test": "jest --config=jest.config.js",
  },
  "devDependencies": {
    "@types/pegjs": "0.10.3",
    "@types/jest": "29.1.1",
    "ts-loader": "9.3.1",
    "typescript": "4.8.3",
    "webpack": "5.74.0",
    "webpack-cli": "4.10.0",
    "jest": "29.1.2",
    "ts-jest": "29.0.3"
  },
  "dependencies": {
    "@proj/pkg2": "1.0.0"
  }
}
Run Code Online (Sandbox Code Playgroud)

测试文件c1.test.ts为:

import { Component1 } from "@proj/pkg2";

describe("some tests", () => {
    test("a test case", () => {
        // Arrange ...
        // Act ...
        // Assert ...
    });
});

Run Code Online (Sandbox Code Playgroud)

问题

当我从项目的根目录运行:时npm run test:pkg1,我得到:

    > 1 | import { Component1 } from "@proj/pkg2";
        | ^
      3 | describe("some tests", () => {
      4 | test("a test case", () => {
      5 | // Arrange

      at Resolver._throwModNotFoundError (../../node_modules/jest-resolve/build/resolver.js:487:11)
Run Code Online (Sandbox Code Playgroud)

开玩笑找不到"@proj/pkg2"。这是有道理的,因为它无法理解工作区,并且 Jest 在运行测试之前编译所有文件。怎么解决这个问题呢?