Migrating from yarn to pnpm – ENOENT errors in jest tests

I am trying to migrate a yarn based monorepo to pnpm. For the context, the repo contains a shared folder, which most other projects use. We are using Jest v26 with React v17, and node v20.

I am having problems with jest-based tests. With yarn, everything works smoothly. After migrating to pnpm, with no changes to dependencies at all, I’m getting this error for every test suite:

 FAIL  tests/[redacted].test.ts Test suite failed to run

ENOENT: no such file or directory, open '[redacted - project directory]node:os'

  at Runtime.readFile (../../node_modules/.pnpm/[email protected][email protected][email protected]_/node_modules/jest-runtime/build/index.js:1987:21)
  at Object.<anonymous> (../../node_modules/.pnpm/@[email protected]/node_modules/@azure/logger/src/log.ts:4:1)
  at Object.<anonymous> (../../node_modules/.pnpm/@[email protected]/node_modules/@azure/logger/src/debug.ts:4:1)
  at Object.<anonymous> (../../node_modules/.pnpm/@[email protected]/node_modules/@azure/logger/src/index.ts:4:1)
  at Object.<anonymous> (../../node_modules/.pnpm/@[email protected]/node_modules/@azure/core-rest-pipeline/src/log.ts:4:1)
  at Object.<anonymous> (../../node_modules/.pnpm/@[email protected]/node_modules/@azure/core-rest-pipeline/src/policies/logPolicy.ts:7:1)
  at Object.<anonymous> (../../node_modules/.pnpm/@[email protected]/node_modules/@azure/core-rest-pipeline/src/createPipelineFromOptions.ts:4:1)
  at Object.<anonymous> (../../node_modules/.pnpm/@[email protected]/node_modules/@azure/core-rest-pipeline/src/index.ts:43:1)
  at Object.<anonymous> (../../node_modules/.pnpm/@[email protected]/node_modules/@azure-rest/core-client/src/restError.ts:4:1)
  at Object.<anonymous> (../../node_modules/.pnpm/@[email protected]/node_modules/@azure-rest/core-client/src/index.ts:9:1)

The *.ts files from the log above do not exist in my filesystem – I have tried opening the exact path from the logs, and I also browsed the node_modules directory. I have no idea where this comes from.

One of the possible solutions I have found on the internet is to migrate to Jest v27 or higher, which indeed solves the issue above. However, v27 comes with breaking changes that breaks a lot of other tests for different reasons.

I have three questions:

  1. Why the tests work fine with packages installed via yarn, but fail with packages installed via pnpm?
  2. Why are there paths in the logs mentioned above, that do not exist, yet seem to be resolved fine by jest, considering the error stack?
  3. Is there any way to resolve this issue, using pnpm but without upgrading jest to v27?

My jest config:

module.exports = {
    preset: "ts-jest",
    setupFilesAfterEnv: ["./tests/setupTests.ts", "./tests/setupMocks.ts"],
    moduleFileExtensions: ["js", "json", "jsx", "ts", "tsx"],
    modulePaths: ["src", "test"],
    moduleDirectories: ["node_modules", "shared"],
    moduleNameMapper: {
        "^.+\.(css|less|scss)$": "<rootDir>/tests/mocks/styleMock.js",
        "^@ProjectNameMocks(.*)$": "<rootDir>/storybook/stories/mocks$1",
        "^@ProjectNameTests(.*)$": "<rootDir>/tests$1",
        "^@ProjectName(.*)$": "<rootDir>/src$1"
    },
    testEnvironment: "jsdom",
    transform: {
        "^.+\.(js|jsx)?$": "babel-jest"
    },
    transformIgnorePatterns: ["/node_modules/(?!(\.pnpm|lodash-es|@fluentui|@azure))"],
    modulePathIgnorePatterns: ["./bin"],
    globals: {
        "ts-jest": {
            tsconfig: "./tsconfig.json"
        }
    }
};

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật