Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yarn 2 and Plug'n'Play #1857

Closed
alexkuc opened this issue Aug 4, 2020 · 11 comments · Fixed by #1859
Closed

Yarn 2 and Plug'n'Play #1857

alexkuc opened this issue Aug 4, 2020 · 11 comments · Fixed by #1859
Labels
🐛 Bug Confirmed Bug is confirmed

Comments

@alexkuc
Copy link

alexkuc commented Aug 4, 2020

🐛 Bug Report

When using Yarn 2 with Plug'n'Play feature, I get a number of errors like:

(node:57379) [MODULE_NOT_FOUND] Error: ts-jest tried to access @types/jest, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

To Reproduce

Steps to reproduce the behavior:

https://github.com/alexkuc/ts-jest-yarn-2-bug

  1. git clone
  2. assuming starting with classic yarn (v1)
  3. yarn install
  4. yarn test
  5. yarn set version berry
  6. yarn install
  7. yarn test
  8. switch Yarn PnP to node-modules (e.g. How to turn off yarn@2 PnP?
  9. yarn test

Expected behavior

Yarn error [MODULE_NOT_FOUND] should not occur.

Link to repo (highly encouraged)

https://github.com/alexkuc/ts-jest-yarn-2-bug

Debug log:

{"context":{"allowJs":false,"logLevel":20,"namespace":"jest-preset","package":"ts-jest","version":"26.1.4"},"message":"creating jest presets not handling JavaScript files","sequence":1,"time":"2020-08-04T16:11:11.262Z"}
{"context":{"logLevel":20,"namespace":"Importer","package":"ts-jest","version":"26.1.4"},"message":"creating Importer singleton","sequence":2,"time":"2020-08-04T16:11:14.484Z"}
{"context":{"allowJs":false,"logLevel":20,"namespace":"jest-preset","package":"ts-jest","version":"26.1.4"},"message":"creating jest presets not handling JavaScript files","sequence":3,"time":"2020-08-04T16:11:14.495Z"}
{"context":{"actualVersion":"26.2.2","expectedVersion":">=26 <27","logLevel":20,"namespace":"versions","package":"ts-jest","version":"26.1.4"},"message":"checking version of jest: OK","sequence":4,"time":"2020-08-04T16:11:14.501Z"}
{"context":{"baseOptions":{},"logLevel":20,"namespace":"jest-transformer","package":"ts-jest","transformerId":1,"version":"26.1.4"},"message":"created new transformer","sequence":5,"time":"2020-08-04T16:11:14.501Z"}
{"context":{"fileName":"/Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug/fizzBuzz.test.ts","logLevel":20,"namespace":"jest-transformer","package":"ts-jest","transformOptions":{"config":{"automock":false,"cache":true,"cacheDirectory":"/private/var/folders/_p/292_lyvd0yg7dg7x9rqgldym0000gn/T/jest_dx","clearMocks":true,"coveragePathIgnorePatterns":["/node_modules/"],"cwd":"/Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug","detectLeaks":false,"detectOpenHandles":false,"errorOnDeprecated":false,"extraGlobals":[],"forceCoverageMatch":[],"globals":{"ts-jest":{"packageJson":"<rootDir>/package.json"}},"haste":{"computeSha1":false,"throwOnModuleCollision":false},"moduleDirectories":["node_modules"],"moduleFileExtensions":["js","json","jsx","ts","tsx","node"],"moduleNameMapper":[],"modulePathIgnorePatterns":[],"name":"cdfe7d1990277dc72edeb7b846199c52","prettierPath":"prettier","resetMocks":false,"resetModules":false,"restoreMocks":false,"rootDir":"/Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug","roots":["/Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug"],"runner":"jest-runner","setupFiles":[],"setupFilesAfterEnv":[],"skipFilter":false,"slowTestThreshold":5,"snapshotSerializers":[],"testEnvironment":"/Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug/.yarn/cache/jest-environment-jsdom-npm-26.2.0-493360024e-65198f8bc5.zip/node_modules/jest-environment-jsdom/build/index.js","testEnvironmentOptions":{},"testLocationInResults":false,"testMatch":["**/__tests__/**/*.[jt]s?(x)","**/?(*.)+(spec|test).[tj]s?(x)"],"testPathIgnorePatterns":["/node_modules/"],"testRegex":[],"testRunner":"/Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug/.yarn/cache/jest-jasmine2-npm-26.2.2-13dab4f95f-b4aa2bee7c.zip/node_modules/jest-jasmine2/build/index.js","testURL":"http://localhost","timers":"real","transform":[["^.+\\.tsx?$","/Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug/.yarn/$$virtual/ts-jest-virtual-f51a8b0beb/0/cache/ts-jest-npm-26.1.4-bae7f255bf-e69d84f07e.zip/node_modules/ts-jest/dist/index.js",{}]],"transformIgnorePatterns":["/node_modules/"],"watchPathIgnorePatterns":[]},"instrument":false,"rootDir":"/Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug","supportsDynamicImport":false,"supportsStaticESM":false},"transformerId":1,"version":"26.1.4"},"message":"computing cache key for /Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug/fizzBuzz.test.ts","sequence":6,"time":"2020-08-04T16:11:14.503Z"}
{"context":{"logLevel":30,"namespace":"jest-transformer","package":"ts-jest","transformerId":1,"version":"26.1.4"},"message":"no matching config-set found, creating a new one","sequence":7,"time":"2020-08-04T16:11:14.503Z"}
{"context":{"config":{"automock":false,"cache":true,"cacheDirectory":"/private/var/folders/_p/292_lyvd0yg7dg7x9rqgldym0000gn/T/jest_dx","clearMocks":true,"coveragePathIgnorePatterns":["/node_modules/"],"cwd":"/Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug","detectLeaks":false,"detectOpenHandles":false,"errorOnDeprecated":false,"extraGlobals":[],"forceCoverageMatch":[],"globals":{"ts-jest":{"packageJson":"<rootDir>/package.json"}},"haste":{"computeSha1":false,"throwOnModuleCollision":false},"moduleDirectories":["node_modules"],"moduleFileExtensions":["js","json","jsx","ts","tsx","node"],"moduleNameMapper":[],"modulePathIgnorePatterns":[],"name":"cdfe7d1990277dc72edeb7b846199c52","prettierPath":"prettier","resetMocks":false,"resetModules":false,"restoreMocks":false,"rootDir":"/Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug","roots":["/Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug"],"runner":"jest-runner","setupFiles":[],"setupFilesAfterEnv":[],"skipFilter":false,"slowTestThreshold":5,"snapshotSerializers":[],"testEnvironment":"/Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug/.yarn/cache/jest-environment-jsdom-npm-26.2.0-493360024e-65198f8bc5.zip/node_modules/jest-environment-jsdom/build/index.js","testEnvironmentOptions":{},"testLocationInResults":false,"testMatch":["**/__tests__/**/*.[jt]s?(x)","**/?(*.)+(spec|test).[tj]s?(x)"],"testPathIgnorePatterns":["/node_modules/"],"testRegex":[],"testRunner":"/Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug/.yarn/cache/jest-jasmine2-npm-26.2.2-13dab4f95f-b4aa2bee7c.zip/node_modules/jest-jasmine2/build/index.js","testURL":"http://localhost","timers":"real","transform":[["^.+\\.tsx?$","/Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug/.yarn/$$virtual/ts-jest-virtual-f51a8b0beb/0/cache/ts-jest-npm-26.1.4-bae7f255bf-e69d84f07e.zip/node_modules/ts-jest/dist/index.js",{}]],"transformIgnorePatterns":["/node_modules/"],"watchPathIgnorePatterns":[]},"logLevel":20,"namespace":"backports","package":"ts-jest","transformerId":1,"version":"26.1.4"},"message":"backporting config","sequence":8,"time":"2020-08-04T16:11:14.504Z"}
{"context":{"jestConfig":{"automock":false,"cache":true,"cacheDirectory":"/private/var/folders/_p/292_lyvd0yg7dg7x9rqgldym0000gn/T/jest_dx","clearMocks":true,"coveragePathIgnorePatterns":["/node_modules/"],"cwd":"/Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug","detectLeaks":false,"detectOpenHandles":false,"errorOnDeprecated":false,"extraGlobals":[],"forceCoverageMatch":[],"globals":{"ts-jest":{"packageJson":"<rootDir>/package.json"}},"haste":{"computeSha1":false,"throwOnModuleCollision":false},"moduleDirectories":["node_modules"],"moduleFileExtensions":["js","json","jsx","ts","tsx","node"],"moduleNameMapper":[],"modulePathIgnorePatterns":[],"name":"cdfe7d1990277dc72edeb7b846199c52","prettierPath":"prettier","resetMocks":false,"resetModules":false,"restoreMocks":false,"rootDir":"/Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug","roots":["/Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug"],"runner":"jest-runner","setupFiles":[],"setupFilesAfterEnv":[],"skipFilter":false,"slowTestThreshold":5,"snapshotSerializers":[],"testEnvironment":"/Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug/.yarn/cache/jest-environment-jsdom-npm-26.2.0-493360024e-65198f8bc5.zip/node_modules/jest-environment-jsdom/build/index.js","testEnvironmentOptions":{},"testLocationInResults":false,"testMatch":["**/__tests__/**/*.[jt]s?(x)","**/?(*.)+(spec|test).[tj]s?(x)"],"testPathIgnorePatterns":["/node_modules/"],"testRegex":[],"testRunner":"/Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug/.yarn/cache/jest-jasmine2-npm-26.2.2-13dab4f95f-b4aa2bee7c.zip/node_modules/jest-jasmine2/build/index.js","testURL":"http://localhost","timers":"real","transform":[["^.+\\.tsx?$","/Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug/.yarn/$$virtual/ts-jest-virtual-f51a8b0beb/0/cache/ts-jest-npm-26.1.4-bae7f255bf-e69d84f07e.zip/node_modules/ts-jest/dist/index.js",{}]],"transformIgnorePatterns":["/node_modules/"],"watchPathIgnorePatterns":[]},"logLevel":20,"namespace":"config","package":"ts-jest","transformerId":1,"version":"26.1.4"},"message":"normalized jest config","sequence":9,"time":"2020-08-04T16:11:14.504Z"}
{"context":{"fromPath":"<rootDir>/package.json","logLevel":20,"namespace":"config","package":"ts-jest","toPath":"/Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug/package.json","transformerId":1,"version":"26.1.4"},"message":"resolved path from <rootDir>/package.json to /Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug/package.json","sequence":10,"time":"2020-08-04T16:11:14.505Z"}
{"context":{"logLevel":20,"namespace":"config","package":"ts-jest","transformerId":1,"tsJestConfig":{"compiler":"typescript","diagnostics":{"ignoreCodes":[6059,18002,18003],"pretty":true,"throws":true},"isolatedModules":false,"packageJson":{"kind":"file","value":"/Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug/package.json"},"transformers":[],"tsConfig":{"kind":"file"}},"version":"26.1.4"},"message":"normalized ts-jest config","sequence":11,"time":"2020-08-04T16:11:14.506Z"}
{"context":{"fromPath":"/Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug/package.json","logLevel":20,"namespace":"config","package":"ts-jest","toPath":"/Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug/package.json","transformerId":1,"version":"26.1.4"},"message":"resolved path from /Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug/package.json to /Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug/package.json","sequence":12,"time":"2020-08-04T16:11:14.507Z"}
{"context":{"logLevel":20,"namespace":"config","package":"ts-jest","transformerId":1,"version":"26.1.4"},"message":"babel is disabled","sequence":13,"time":"2020-08-04T16:11:14.510Z"}
{"context":{"logLevel":20,"namespace":"Importer","package":"ts-jest","requireResult":{"exists":true,"given":"typescript","path":"/Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug/.yarn/cache/typescript-patch-ba0dbfd217-f0d3d9c987.zip/node_modules/typescript/lib/typescript.js"},"version":"26.1.4"},"message":"loaded module typescript","sequence":14,"time":"2020-08-04T16:11:14.512Z"}
{"context":{"logLevel":20,"namespace":"Importer","package":"ts-jest","version":"26.1.4"},"message":"patching typescript","sequence":15,"time":"2020-08-04T16:11:14.512Z"}
{"context":{"actualVersion":"3.9.7","expectedVersion":">=3.8 <4","logLevel":20,"namespace":"versions","package":"ts-jest","version":"26.1.4"},"message":"checking version of typescript: OK","sequence":16,"time":"2020-08-04T16:11:14.513Z"}
{"context":{"logLevel":20,"namespace":"config","package":"ts-jest","transformerId":1,"tsconfig":{"compileOnSave":false,"configFileSpecs":{"includeSpecs":["**/*"],"validatedIncludeSpecs":["**/*"],"wildcardDirectories":{"/Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug":1}},"errors":[],"fileNames":["/Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug/fizzBuzz.test.ts","/Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug/fizzBuzz.ts"],"options":{"declaration":false,"inlineSourceMap":false,"inlineSources":true,"module":1,"noEmit":false,"removeComments":false,"sourceMap":true,"target":1},"raw":{"compileOnSave":false,"compilerOptions":{}},"typeAcquisition":{"enable":false,"exclude":[],"include":[]},"wildcardDirectories":{"/Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug":1}},"version":"26.1.4"},"message":"normalized typescript config","sequence":17,"time":"2020-08-04T16:11:14.522Z"}
{"context":{"fileName":"/Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug/fizzBuzz.ts","logLevel":20,"namespace":"jest-transformer","package":"ts-jest","transformOptions":{"config":{"automock":false,"cache":true,"cacheDirectory":"/private/var/folders/_p/292_lyvd0yg7dg7x9rqgldym0000gn/T/jest_dx","clearMocks":true,"coveragePathIgnorePatterns":["/node_modules/"],"cwd":"/Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug","detectLeaks":false,"detectOpenHandles":false,"errorOnDeprecated":false,"extraGlobals":[],"forceCoverageMatch":[],"globals":{"ts-jest":{"packageJson":"<rootDir>/package.json"}},"haste":{"computeSha1":false,"throwOnModuleCollision":false},"moduleDirectories":["node_modules"],"moduleFileExtensions":["js","json","jsx","ts","tsx","node"],"moduleNameMapper":[],"modulePathIgnorePatterns":[],"name":"cdfe7d1990277dc72edeb7b846199c52","prettierPath":"prettier","resetMocks":false,"resetModules":false,"restoreMocks":false,"rootDir":"/Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug","roots":["/Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug"],"runner":"jest-runner","setupFiles":[],"setupFilesAfterEnv":[],"skipFilter":false,"slowTestThreshold":5,"snapshotSerializers":[],"testEnvironment":"/Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug/.yarn/cache/jest-environment-jsdom-npm-26.2.0-493360024e-65198f8bc5.zip/node_modules/jest-environment-jsdom/build/index.js","testEnvironmentOptions":{},"testLocationInResults":false,"testMatch":["**/__tests__/**/*.[jt]s?(x)","**/?(*.)+(spec|test).[tj]s?(x)"],"testPathIgnorePatterns":["/node_modules/"],"testRegex":[],"testRunner":"/Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug/.yarn/cache/jest-jasmine2-npm-26.2.2-13dab4f95f-b4aa2bee7c.zip/node_modules/jest-jasmine2/build/index.js","testURL":"http://localhost","timers":"real","transform":[["^.+\\.tsx?$","/Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug/.yarn/$$virtual/ts-jest-virtual-f51a8b0beb/0/cache/ts-jest-npm-26.1.4-bae7f255bf-e69d84f07e.zip/node_modules/ts-jest/dist/index.js",{}]],"transformIgnorePatterns":["/node_modules/"],"watchPathIgnorePatterns":[]},"instrument":false,"rootDir":"/Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug","supportsDynamicImport":false,"supportsStaticESM":false},"transformerId":1,"version":"26.1.4"},"message":"computing cache key for /Users/alexkucheryuk/Repositories/GitHub/ts-jest-yarn-2-bug/fizzBuzz.ts","sequence":18,"time":"2020-08-04T16:11:14.524Z"}

envinfo

System:
    OS: OSX

Npm packages:
    jest: ^26.2.2
    ts-jest: ^26.1.4
    typescript: ^3.9.7
    babel(optional): n/a
@alexkuc alexkuc added Bug Report Needs Repo Need a minimium repository to reproduce the problem Needs Triage labels Aug 4, 2020
@ahnpnl
Copy link
Collaborator

ahnpnl commented Aug 4, 2020

The easiest fix is move @types/jest to dependencies ? Or do you have any other suggestions ?

@alexkuc
Copy link
Author

alexkuc commented Aug 4, 2020

I would say it is more of a workaround rather than fix as @types/jest is not needed to compile the source? Isn't typically deps are what is needed to compile the source and devdeps are purely tooling/development deps?

@ahnpnl
Copy link
Collaborator

ahnpnl commented Aug 4, 2020

In the documentation, it is specified explicitly that @types/jest needs to be installed together, seems like yarn 2 is not happy about that way.

@alexkuc
Copy link
Author

alexkuc commented Aug 4, 2020

I think I misunderstood you. Installation was done as per manual, i.e. yarn add --dev jest typescript ts-jest @types/jest.

This is the package.json from the example repository:

{
  "name": "test",
  "version": "1.0.0",
  "main": "index.js",
  "author": "Alexander Kucheryuk <3331946+alexkuc@users.noreply.github.com>",
  "license": "MIT",
  "devDependencies": {
    "@types/jest": "^26.0.8",
    "jest": "^26.2.2",
    "ts-jest": "^26.1.4",
    "typescript": "^3.9.7"
  },
  "scripts": {
    "test": "jest"
  }
}

@ahnpnl
Copy link
Collaborator

ahnpnl commented Aug 4, 2020

ts-jest source shipped to npm doesn’t use @types/jest so I suspect only that tsconfig.build.json extends tsconfig.json and tsconfig.json includes @types/jest

@alexkuc
Copy link
Author

alexkuc commented Aug 4, 2020

Does it mean that I need to change my repository config or is it something on the ts-jest end?

@ahnpnl
Copy link
Collaborator

ahnpnl commented Aug 4, 2020

Oh I don’t know yet, will need to test a few possible theories. One thing I am certain is codes shipped to npm doesn’t use @types/jest

@ahnpnl ahnpnl added 🐛 Bug Confirmed Bug is confirmed and removed Bug Report Needs Repo Need a minimium repository to reproduce the problem Needs Triage labels Aug 5, 2020
@ahnpnl
Copy link
Collaborator

ahnpnl commented Aug 5, 2020

ok I found the issue here

? jest.MockInstance<R, ConstructorArgumentsOf<T>>
. This helper is exported for public usage.

Since this is a public API, the only way to fix the problem is adding @types/jest to dependencies list

@ahnpnl
Copy link
Collaborator

ahnpnl commented Aug 5, 2020

Hmm maybe import type syntax can solve this ? Gonna try that

Unfortunately, it doesn't work, so the only solution is moving @types/jest to dependencies

@alexkuc
Copy link
Author

alexkuc commented Aug 6, 2020

Thank you!

@ahnpnl
Copy link
Collaborator

ahnpnl commented Mar 8, 2021

I have reverted #1859 and retested with latest yarn 2 and it seemed like Yarn 2 has improved so the warning [MODULE_NOT_FOUND] doesn't show anymore.

@ahnpnl ahnpnl closed this as completed Mar 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug Confirmed Bug is confirmed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants