简体   繁体   中英

Why is pnpm using a different version to the one in package.json

My package.json contains this:

  "devDependencies": {
    "typescript": "~4.6.2",
    "jest": "~27.5.1",
    "ts-jest": "~27.1.3",
    "@types/jest": "~27.4.1",
    "@types/uuid": "~8.3.0"
  },

I get an error like this when I run pnpm run test :


 FAIL  test/types/combineModelsByPropertyNameAndType.spec.ts
  ● Test suite failed to run

    TypeError: Jest: a transform must export a `process` function.

      at ScriptTransformer._getTransformer (../../node_modules/.pnpm/@jest+transform@26.6.2/node_modules/@jest/transform/build/ScriptTransformer.js:360:13)
      at ScriptTransformer.transformSource (../../node_modules/.pnpm/@jest+transform@26.6.2/node_modules/@jest/transform/build/ScriptTransformer.js:427:28)
      at ScriptTransformer._transformAndBuildScript (../../node_modules/.pnpm/@jest+transform@26.6.2/node_modules/@jest/transform/build/ScriptTransformer.js:569:40)
      at ScriptTransformer.transform (../../node_modules/.pnpm/@jest+transform@26.6.2/node_modules/@jest/transform/build/ScriptTransformer.js:607:25)

So despite stating in devDependencies that jest 27 should be used, its using version 26 in actuality - which is the cause of that error from jest.

For context: I am using turborepo as my monorepo management tool, and other modules in my monorepo do use jest 26. So I am not sure if this is a pnpm question or a turborepo question

Looks like it might be this issue . If that is the case, a workaround currently is to set the hoist=false in the root .npmrc , remove node_modules and reinstall.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM