Issue
I’m getting an Unable to require .d.ts file
error when including a TS module from the node_modules folder. I managed to reproduce the bug in a minimal repo: when linking a module with npm link
, the build works fine but when copying the same code to node_modules
Jest spits out the error.
Note that this reproduces ONLY on Linux / Mac but works fine on Windows.
To me it’s extremely weird that the same code builds on Windows but doesn’t build on Linux; even more weird the fact that the same code compiles when it’s symlinked to node_modules but doesn’t compile when it’s copied to node_modules.
Note that the solution applied in issue #205 fixes the problem in the minimal repo but it does not fix the problem in the original repo. Due to the nature of the bug (windows / linux, symlink / copy) I tend to think that this fix is rather a workaround than a complete fix to the actual problem. If the include
list in tsconfig.json
would be the culprit, it shouldn’t work on a symlinked repo, nor on Windows.
While trying to reproduce the bug in a minimal repo, I was getting inconsistent results. Sometimes the build succeeded, sometimes it didn’t. I’d call it was quasi-random, or just I didn’t manage to catch the logic.
Could the problem be caused by ts-jest
getting the list of files in a different order on Windows / Linux or from symlinked / copied modules and transforming them in different order? Could the file creation or last modification / access dates cause inconsistencies of this kind?
Debug log
Test suite failed to run
TypeError: Unable to require `.d.ts` file.
This is usually the result of a faulty configuration or import. Make sure there is a `.js`, `.json` or another executable extension available alongside `index.ts`.
> 1 | import { callA, anotherCallA } from "localLib";
| ^
2 |
3 | export function checkB(s: string) : string | null {
4 | const a = callA(anotherCallA(s));
at getOutput (node_modules/ts-jest/dist/compiler.js:163:23)
at Object.<anonymous> (src/b.ts:1:1)
Test Suites: 1 failed, 1 total
```
{"context":{"allowJs":false,"logLevel":20,"namespace":"jest-preset","package":"ts-jest","version":"23.10.5"},"message":"creating jest presets not handling JavaScript files","sequence":1,"time":"2019-01-17T08:52:10.218Z"}
{"context":{"logLevel":20,"namespace":"Importer","package":"ts-jest","version":"23.10.5"},"message":"creating Importer singleton","sequence":2,"time":"2019-01-17T08:52:10.866Z"}
{"context":{"allowJs":false,"logLevel":20,"namespace":"jest-preset","package":"ts-jest","version":"23.10.5"},"message":"creating jest presets not handling JavaScript files","sequence":3,"time":"2019-01-17T08:52:10.869Z"}
{"context":{"actualVersion":"23.6.0","expectedVersion":">=22 <24","logLevel":20,"namespace":"versions","package":"ts-jest","version":"23.10.5"},"message":"checking version of jest: OK","sequence":4,"time":"2019-01-17T08:52:10.873Z"}
{"context":{"baseOptions":{},"logLevel":20,"namespace":"jest-transformer","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"created new transformer","sequence":5,"time":"2019-01-17T08:52:10.873Z"}
{"context":{"fileName":"/home/hernyo/code/jest-build-error/main/src/__tests__/b.test.ts","logLevel":20,"namespace":"jest-transformer","package":"ts-jest","transformOptions":{"instrument":false,"rootDir":"/home/hernyo/code/jest-build-error/main"},"transformerId":1,"version":"23.10.5"},"message":"computing cache key for /home/hernyo/code/jest-build-error/main/src/__tests__/b.test.ts","sequence":6,"time":"2019-01-17T08:52:10.874Z"}
{"context":{"logLevel":30,"namespace":"jest-transformer","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"no matching config-set found, creating a new one","sequence":7,"time":"2019-01-17T08:52:10.875Z"}
{"context":{"config":{"automock":false,"browser":false,"cache":true,"cacheDirectory":"/tmp/jest_rs","clearMocks":false,"coveragePathIgnorePatterns":["/node_modules/"],"cwd":"/home/hernyo/code/jest-build-error/main","detectLeaks":false,"detectOpenHandles":false,"errorOnDeprecated":false,"filter":null,"forceCoverageMatch":[],"globals":{"ts-jest":{"tsConfigFile":"tsconfig.json"}},"haste":{"providesModuleNodeModules":[]},"moduleDirectories":["node_modules"],"moduleFileExtensions":["ts","tsx","js"],"moduleNameMapper":{},"modulePathIgnorePatterns":[],"name":"27587b33ddb40cf53c4cddf1855dde36","prettierPath":null,"resetMocks":false,"resetModules":false,"resolver":null,"restoreMocks":false,"rootDir":"/home/hernyo/code/jest-build-error/main","roots":["/home/hernyo/code/jest-build-error/main"],"runner":"jest-runner","setupFiles":[],"setupTestFrameworkScriptFile":null,"skipFilter":false,"snapshotSerializers":[],"testEnvironment":"/home/hernyo/code/jest-build-error/main/node_modules/jest-environment-node/build/index.js","testEnvironmentOptions":{},"testLocationInResults":false,"testMatch":[],"testPathIgnorePatterns":["/node_modules/"],"testRegex":"(.*(\\.|/)(test|spec))\\.(jsx?|tsx?)$","testRunner":"/home/hernyo/code/jest-build-error/main/node_modules/jest-jasmine2/build/index.js","testURL":"http://localhost","timers":"real","transform":[["^.+\\.(ts|tsx)$","/home/hernyo/code/jest-build-error/main/node_modules/ts-jest/dist/index.js"],["^.+\\.tsx?$","/home/hernyo/code/jest-build-error/main/node_modules/ts-jest/dist/index.js"]],"transformIgnorePatterns":["/node_modules/(?!(localLib)).*$"],"watchPathIgnorePatterns":[]},"logLevel":20,"namespace":"backports","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"backporting config","sequence":8,"time":"2019-01-17T08:52:10.875Z"}
{"context":{"logLevel":40,"namespace":"backports","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"\"[jest-config].globals.ts-jest.tsConfigFile\" is deprecated, use \"[jest-config].globals.ts-jest.tsConfig\" instead.","sequence":9,"time":"2019-01-17T08:52:10.876Z"}
{"context":{"logLevel":40,"namespace":"backports","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"Your Jest configuration is outdated. Use the CLI to help migrating it: ts-jest config:migrate <config-file>.","sequence":10,"time":"2019-01-17T08:52:10.876Z"}
{"context":{"jestConfig":{"automock":false,"browser":false,"cache":true,"cacheDirectory":"/tmp/jest_rs","clearMocks":false,"coveragePathIgnorePatterns":["/node_modules/"],"cwd":"/home/hernyo/code/jest-build-error/main","detectLeaks":false,"detectOpenHandles":false,"errorOnDeprecated":false,"filter":null,"forceCoverageMatch":[],"globals":{"ts-jest":{"tsConfig":"tsconfig.json"}},"haste":{"providesModuleNodeModules":[]},"moduleDirectories":["node_modules"],"moduleFileExtensions":["ts","tsx","js"],"moduleNameMapper":{},"modulePathIgnorePatterns":[],"name":"27587b33ddb40cf53c4cddf1855dde36","prettierPath":null,"resetMocks":false,"resetModules":false,"resolver":null,"restoreMocks":false,"rootDir":"/home/hernyo/code/jest-build-error/main","roots":["/home/hernyo/code/jest-build-error/main"],"runner":"jest-runner","setupFiles":[],"setupTestFrameworkScriptFile":null,"skipFilter":false,"snapshotSerializers":[],"testEnvironment":"/home/hernyo/code/jest-build-error/main/node_modules/jest-environment-node/build/index.js","testEnvironmentOptions":{},"testLocationInResults":false,"testMatch":[],"testPathIgnorePatterns":["/node_modules/"],"testRegex":"(.*(\\.|/)(test|spec))\\.(jsx?|tsx?)$","testRunner":"/home/hernyo/code/jest-build-error/main/node_modules/jest-jasmine2/build/index.js","testURL":"http://localhost","timers":"real","transform":[["^.+\\.(ts|tsx)$","/home/hernyo/code/jest-build-error/main/node_modules/ts-jest/dist/index.js"],["^.+\\.tsx?$","/home/hernyo/code/jest-build-error/main/node_modules/ts-jest/dist/index.js"]],"transformIgnorePatterns":["/node_modules/(?!(localLib)).*$"],"watchPathIgnorePatterns":[]},"logLevel":20,"namespace":"config","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"normalized jest config","sequence":11,"time":"2019-01-17T08:52:10.876Z"}
{"context":{"fromPath":"tsconfig.json","logLevel":20,"namespace":"config","package":"ts-jest","toPath":"/home/hernyo/code/jest-build-error/main/tsconfig.json","transformerId":1,"version":"23.10.5"},"message":"resolved path from tsconfig.json to /home/hernyo/code/jest-build-error/main/tsconfig.json","sequence":12,"time":"2019-01-17T08:52:10.876Z"}
{"context":{"logLevel":20,"namespace":"config","package":"ts-jest","transformerId":1,"tsJestConfig":{"compiler":"typescript","diagnostics":{"ignoreCodes":[6059,18002,18003],"pretty":true,"throws":true},"isolatedModules":false,"transformers":[],"tsConfig":{"kind":"file","value":"/home/hernyo/code/jest-build-error/main/tsconfig.json"}},"version":"23.10.5"},"message":"normalized ts-jest config","sequence":13,"time":"2019-01-17T08:52:10.880Z"}
{"context":{"logLevel":20,"namespace":"config","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"babel is disabled","sequence":14,"time":"2019-01-17T08:52:10.882Z"}
{"context":{"logLevel":20,"namespace":"Importer","package":"ts-jest","requireResult":{"exists":true,"given":"typescript","path":"/home/hernyo/code/jest-build-error/main/node_modules/typescript/lib/typescript.js"},"version":"23.10.5"},"message":"loaded module typescript","sequence":15,"time":"2019-01-17T08:52:11.139Z"}
{"context":{"logLevel":20,"namespace":"Importer","package":"ts-jest","version":"23.10.5"},"message":"patching typescript","sequence":16,"time":"2019-01-17T08:52:11.139Z"}
{"context":{"actualVersion":"3.2.2","expectedVersion":">=2.7 <4","logLevel":20,"namespace":"versions","package":"ts-jest","version":"23.10.5"},"message":"checking version of typescript: OK","sequence":17,"time":"2019-01-17T08:52:11.140Z"}
{"context":{"logLevel":20,"namespace":"config","package":"ts-jest","transformerId":1,"tsConfigFileName":"/home/hernyo/code/jest-build-error/main/tsconfig.json","version":"23.10.5"},"message":"readTsConfig(): reading /home/hernyo/code/jest-build-error/main/tsconfig.json","sequence":18,"time":"2019-01-17T08:52:11.140Z"}
{"context":{"logLevel":20,"namespace":"config","package":"ts-jest","transformerId":1,"tsconfig":{"input":{"compilerOptions":{"esModuleInterop":true,"module":"commonjs","strict":true,"target":"es5"}},"resolved":{"compileOnSave":false,"configFileSpecs":{"includeSpecs":["**/*"],"validatedIncludeSpecs":["**/*"],"wildcardDirectories":{"/home/hernyo/code/jest-build-error/main":1}},"errors":[],"fileNames":["/home/hernyo/code/jest-build-error/main/src/b.ts","/home/hernyo/code/jest-build-error/main/src/__tests__/b.test.ts"],"options":{"configFilePath":"/home/hernyo/code/jest-build-error/main/tsconfig.json","declaration":false,"esModuleInterop":true,"inlineSourceMap":false,"inlineSources":true,"module":1,"noEmit":false,"outDir":"$$ts-jest$$","removeComments":false,"sourceMap":true,"strict":true,"target":1},"raw":{"compileOnSave":false,"compilerOptions":{"esModuleInterop":true,"module":"commonjs","strict":true,"target":"es5"}},"typeAcquisition":{"enable":false,"exclude":[],"include":[]},"wildcardDirectories":{"/home/hernyo/code/jest-build-error/main":1}}},"version":"23.10.5"},"message":"normalized typescript config","sequence":19,"time":"2019-01-17T08:52:11.156Z"}
{"context":{"fileName":"/home/hernyo/code/jest-build-error/main/src/__tests__/b.test.ts","logLevel":20,"namespace":"jest-transformer","package":"ts-jest","transformOptions":{"instrument":false},"transformerId":1,"version":"23.10.5"},"message":"processing /home/hernyo/code/jest-build-error/main/src/__tests__/b.test.ts","sequence":20,"time":"2019-01-17T08:52:11.158Z"}
{"context":{"logLevel":20,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"creating typescript compiler (language service)","sequence":21,"time":"2019-01-17T08:52:11.159Z"}
{"context":{"cacheDirectory":"/tmp/jest_rs/ts-jest/42/fba554c02ecdb7ea5a83eedadc81264af1218c","logLevel":20,"namespace":"config","package":"ts-jest","version":"23.10.5"},"message":"will use file caching","sequence":22,"time":"2019-01-17T08:52:11.159Z"}
{"context":{"logLevel":20,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"creating language service","sequence":23,"time":"2019-01-17T08:52:11.160Z"}
{"context":{"fileName":"/home/hernyo/code/jest-build-error/main/src/__tests__/b.test.ts","logLevel":20,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"readThrough(): cache miss","sequence":24,"time":"2019-01-17T08:52:11.162Z"}
{"context":{"fileName":"/home/hernyo/code/jest-build-error/main/src/__tests__/b.test.ts","logLevel":20,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getOutput(): compiling using language service","sequence":25,"time":"2019-01-17T08:52:11.162Z"}
{"context":{"fileName":"/home/hernyo/code/jest-build-error/main/src/__tests__/b.test.ts","logLevel":20,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"updateMemoryCache()","sequence":26,"time":"2019-01-17T08:52:11.163Z"}
{"context":{"cacheHit":false,"fileName":"/home/hernyo/code/jest-build-error/main/src/b.ts","logLevel":10,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getScriptSnapshot(): cache miss","sequence":27,"time":"2019-01-17T08:52:11.163Z"}
{"context":{"cacheHit":true,"fileName":"/home/hernyo/code/jest-build-error/main/src/__tests__/b.test.ts","logLevel":10,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getScriptSnapshot(): cache hit","sequence":28,"time":"2019-01-17T08:52:11.164Z"}
{"context":{"call":null,"logLevel":10,"namespace":"ts:serviceHost","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"readFile","sequence":29,"time":"2019-01-17T08:52:11.179Z"}
{"context":{"cacheHit":false,"fileName":"/home/hernyo/code/jest-build-error/main/node_modules/localLib/index.ts","logLevel":10,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getScriptSnapshot(): cache miss","sequence":30,"time":"2019-01-17T08:52:11.181Z"}
{"context":{"call":null,"logLevel":10,"namespace":"ts:serviceHost","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"readFile","sequence":31,"time":"2019-01-17T08:52:11.182Z"}
{"context":{"call":null,"logLevel":10,"namespace":"ts:serviceHost","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"readFile","sequence":32,"time":"2019-01-17T08:52:11.183Z"}
{"context":{"cacheHit":false,"fileName":"/home/hernyo/code/jest-build-error/main/node_modules/localLib/src/callA.ts","logLevel":10,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getScriptSnapshot(): cache miss","sequence":33,"time":"2019-01-17T08:52:11.184Z"}
{"context":{"cacheHit":false,"fileName":"/home/hernyo/code/jest-build-error/main/node_modules/localLib/src/anotherCallA.ts","logLevel":10,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getScriptSnapshot(): cache miss","sequence":34,"time":"2019-01-17T08:52:11.185Z"}
{"context":{"call":null,"logLevel":10,"namespace":"ts:serviceHost","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"readFile","sequence":35,"time":"2019-01-17T08:52:11.187Z"}
{"context":{"call":null,"logLevel":10,"namespace":"ts:serviceHost","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"readFile","sequence":36,"time":"2019-01-17T08:52:11.194Z"}
{"context":{"cacheHit":false,"fileName":"/home/hernyo/code/jest-build-error/main/node_modules/@types/jest/index.d.ts","logLevel":10,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getScriptSnapshot(): cache miss","sequence":37,"time":"2019-01-17T08:52:11.199Z"}
{"context":{"cacheHit":false,"fileName":"/home/hernyo/code/jest-build-error/main/node_modules/typescript/lib/lib.d.ts","logLevel":10,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getScriptSnapshot(): cache miss","sequence":38,"time":"2019-01-17T08:52:11.345Z"}
{"context":{"cacheHit":false,"fileName":"/home/hernyo/code/jest-build-error/main/node_modules/typescript/lib/lib.es5.d.ts","logLevel":10,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getScriptSnapshot(): cache miss","sequence":39,"time":"2019-01-17T08:52:11.346Z"}
{"context":{"cacheHit":false,"fileName":"/home/hernyo/code/jest-build-error/main/node_modules/typescript/lib/lib.dom.d.ts","logLevel":10,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getScriptSnapshot(): cache miss","sequence":40,"time":"2019-01-17T08:52:11.515Z"}
{"context":{"cacheHit":false,"fileName":"/home/hernyo/code/jest-build-error/main/node_modules/typescript/lib/lib.webworker.importscripts.d.ts","logLevel":10,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getScriptSnapshot(): cache miss","sequence":41,"time":"2019-01-17T08:52:11.886Z"}
{"context":{"cacheHit":false,"fileName":"/home/hernyo/code/jest-build-error/main/node_modules/typescript/lib/lib.scripthost.d.ts","logLevel":10,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getScriptSnapshot(): cache miss","sequence":42,"time":"2019-01-17T08:52:11.886Z"}
{"context":{"call":null,"logLevel":20,"namespace":"ts-hoisting","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"visitSourceFileNode(): hoisting","sequence":43,"time":"2019-01-17T08:52:12.488Z"}
{"context":{"fileName":"/home/hernyo/code/jest-build-error/main/src/__tests__/b.test.ts","logLevel":20,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getOutput(): computing diagnostics","sequence":44,"time":"2019-01-17T08:52:12.517Z"}
{"context":{"cacheHit":true,"fileName":"/home/hernyo/code/jest-build-error/main/src/b.ts","logLevel":10,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getScriptSnapshot(): cache hit","sequence":45,"time":"2019-01-17T08:52:12.517Z"}
{"context":{"cacheHit":true,"fileName":"/home/hernyo/code/jest-build-error/main/src/__tests__/b.test.ts","logLevel":10,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getScriptSnapshot(): cache hit","sequence":46,"time":"2019-01-17T08:52:12.517Z"}
{"context":{"cacheHit":true,"fileName":"/home/hernyo/code/jest-build-error/main/src/b.ts","logLevel":10,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getScriptSnapshot(): cache hit","sequence":47,"time":"2019-01-17T08:52:12.517Z"}
{"context":{"cacheHit":true,"fileName":"/home/hernyo/code/jest-build-error/main/src/__tests__/b.test.ts","logLevel":10,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getScriptSnapshot(): cache hit","sequence":48,"time":"2019-01-17T08:52:12.518Z"}
{"context":{"cacheHit":true,"fileName":"/home/hernyo/code/jest-build-error/main/src/b.ts","logLevel":10,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getScriptSnapshot(): cache hit","sequence":49,"time":"2019-01-17T08:52:12.518Z"}
{"context":{"cacheHit":true,"fileName":"/home/hernyo/code/jest-build-error/main/src/__tests__/b.test.ts","logLevel":10,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getScriptSnapshot(): cache hit","sequence":50,"time":"2019-01-17T08:52:12.518Z"}
{"context":{"fileName":"/home/hernyo/code/jest-build-error/main/src/__tests__/b.test.ts","logLevel":20,"namespace":"ts-compiler","outputPath":"/tmp/jest_rs/ts-jest/42/fba554c02ecdb7ea5a83eedadc81264af1218c/2815a5d0e0bcfb21f319d82ec6f410a635e912d8.js","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"readThrough(): writing caches","sequence":51,"time":"2019-01-17T08:52:12.519Z"}
{"context":{"fileName":"/home/hernyo/code/jest-build-error/main/src/b.ts","logLevel":20,"namespace":"jest-transformer","package":"ts-jest","transformOptions":{"instrument":false,"rootDir":"/home/hernyo/code/jest-build-error/main"},"transformerId":1,"version":"23.10.5"},"message":"computing cache key for /home/hernyo/code/jest-build-error/main/src/b.ts","sequence":52,"time":"2019-01-17T08:52:12.538Z"}
{"context":{"fileName":"/home/hernyo/code/jest-build-error/main/src/b.ts","logLevel":20,"namespace":"jest-transformer","package":"ts-jest","transformOptions":{"instrument":false},"transformerId":1,"version":"23.10.5"},"message":"processing /home/hernyo/code/jest-build-error/main/src/b.ts","sequence":53,"time":"2019-01-17T08:52:12.538Z"}
{"context":{"fileName":"/home/hernyo/code/jest-build-error/main/src/b.ts","logLevel":20,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"readThrough(): cache miss","sequence":54,"time":"2019-01-17T08:52:12.538Z"}
{"context":{"fileName":"/home/hernyo/code/jest-build-error/main/src/b.ts","logLevel":20,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getOutput(): compiling using language service","sequence":55,"time":"2019-01-17T08:52:12.538Z"}
{"context":{"fileName":"/home/hernyo/code/jest-build-error/main/src/b.ts","logLevel":20,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"updateMemoryCache()","sequence":56,"time":"2019-01-17T08:52:12.538Z"}
{"context":{"cacheHit":true,"fileName":"/home/hernyo/code/jest-build-error/main/src/b.ts","logLevel":10,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getScriptSnapshot(): cache hit","sequence":57,"time":"2019-01-17T08:52:12.538Z"}
{"context":{"cacheHit":true,"fileName":"/home/hernyo/code/jest-build-error/main/src/__tests__/b.test.ts","logLevel":10,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getScriptSnapshot(): cache hit","sequence":58,"time":"2019-01-17T08:52:12.538Z"}
{"context":{"call":null,"logLevel":20,"namespace":"ts-hoisting","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"visitSourceFileNode(): hoisting","sequence":59,"time":"2019-01-17T08:52:12.544Z"}
{"context":{"fileName":"/home/hernyo/code/jest-build-error/main/src/b.ts","logLevel":20,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getOutput(): computing diagnostics","sequence":60,"time":"2019-01-17T08:52:12.554Z"}
{"context":{"cacheHit":true,"fileName":"/home/hernyo/code/jest-build-error/main/src/b.ts","logLevel":10,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getScriptSnapshot(): cache hit","sequence":61,"time":"2019-01-17T08:52:12.554Z"}
{"context":{"cacheHit":true,"fileName":"/home/hernyo/code/jest-build-error/main/src/__tests__/b.test.ts","logLevel":10,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getScriptSnapshot(): cache hit","sequence":62,"time":"2019-01-17T08:52:12.554Z"}
{"context":{"cacheHit":true,"fileName":"/home/hernyo/code/jest-build-error/main/src/b.ts","logLevel":10,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getScriptSnapshot(): cache hit","sequence":63,"time":"2019-01-17T08:52:12.555Z"}
{"context":{"cacheHit":true,"fileName":"/home/hernyo/code/jest-build-error/main/src/__tests__/b.test.ts","logLevel":10,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getScriptSnapshot(): cache hit","sequence":64,"time":"2019-01-17T08:52:12.555Z"}
{"context":{"cacheHit":true,"fileName":"/home/hernyo/code/jest-build-error/main/src/b.ts","logLevel":10,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getScriptSnapshot(): cache hit","sequence":65,"time":"2019-01-17T08:52:12.555Z"}
{"context":{"cacheHit":true,"fileName":"/home/hernyo/code/jest-build-error/main/src/__tests__/b.test.ts","logLevel":10,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getScriptSnapshot(): cache hit","sequence":66,"time":"2019-01-17T08:52:12.555Z"}
{"context":{"fileName":"/home/hernyo/code/jest-build-error/main/src/b.ts","logLevel":20,"namespace":"ts-compiler","outputPath":"/tmp/jest_rs/ts-jest/42/fba554c02ecdb7ea5a83eedadc81264af1218c/848166436f849c74b9aaf7bb41498c3f9844355c.js","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"readThrough(): writing caches","sequence":67,"time":"2019-01-17T08:52:12.555Z"}
{"context":{"fileName":"/home/hernyo/code/jest-build-error/main/node_modules/localLib/index.ts","logLevel":20,"namespace":"jest-transformer","package":"ts-jest","transformOptions":{"instrument":false,"rootDir":"/home/hernyo/code/jest-build-error/main"},"transformerId":1,"version":"23.10.5"},"message":"computing cache key for /home/hernyo/code/jest-build-error/main/node_modules/localLib/index.ts","sequence":68,"time":"2019-01-17T08:52:12.561Z"}
{"context":{"fileName":"/home/hernyo/code/jest-build-error/main/node_modules/localLib/index.ts","logLevel":20,"namespace":"jest-transformer","package":"ts-jest","transformOptions":{"instrument":false},"transformerId":1,"version":"23.10.5"},"message":"processing /home/hernyo/code/jest-build-error/main/node_modules/localLib/index.ts","sequence":69,"time":"2019-01-17T08:52:12.561Z"}
{"context":{"fileName":"/home/hernyo/code/jest-build-error/main/node_modules/localLib/index.ts","logLevel":20,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"readThrough(): cache miss","sequence":70,"time":"2019-01-17T08:52:12.561Z"}
{"context":{"fileName":"/home/hernyo/code/jest-build-error/main/node_modules/localLib/index.ts","logLevel":20,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getOutput(): compiling using language service","sequence":71,"time":"2019-01-17T08:52:12.561Z"}
{"context":{"fileName":"/home/hernyo/code/jest-build-error/main/node_modules/localLib/index.ts","logLevel":20,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"updateMemoryCache()","sequence":72,"time":"2019-01-17T08:52:12.561Z"}
{"context":{"cacheHit":true,"fileName":"/home/hernyo/code/jest-build-error/main/src/b.ts","logLevel":10,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getScriptSnapshot(): cache hit","sequence":73,"time":"2019-01-17T08:52:12.561Z"}
{"context":{"cacheHit":true,"fileName":"/home/hernyo/code/jest-build-error/main/src/__tests__/b.test.ts","logLevel":10,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getScriptSnapshot(): cache hit","sequence":74,"time":"2019-01-17T08:52:12.561Z"}
{"context":{"fileName":"/home/hernyo/code/jest-build-error/main/node_modules/localLib/index.ts","logLevel":20,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getOutput(): computing diagnostics","sequence":75,"time":"2019-01-17T08:52:12.562Z"}
{"context":{"cacheHit":true,"fileName":"/home/hernyo/code/jest-build-error/main/src/b.ts","logLevel":10,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getScriptSnapshot(): cache hit","sequence":76,"time":"2019-01-17T08:52:12.562Z"}
{"context":{"cacheHit":true,"fileName":"/home/hernyo/code/jest-build-error/main/src/__tests__/b.test.ts","logLevel":10,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getScriptSnapshot(): cache hit","sequence":77,"time":"2019-01-17T08:52:12.562Z"}
{"context":{"cacheHit":true,"fileName":"/home/hernyo/code/jest-build-error/main/src/b.ts","logLevel":10,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getScriptSnapshot(): cache hit","sequence":78,"time":"2019-01-17T08:52:12.562Z"}
{"context":{"cacheHit":true,"fileName":"/home/hernyo/code/jest-build-error/main/src/__tests__/b.test.ts","logLevel":10,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getScriptSnapshot(): cache hit","sequence":79,"time":"2019-01-17T08:52:12.562Z"}
{"context":{"cacheHit":true,"fileName":"/home/hernyo/code/jest-build-error/main/src/b.ts","logLevel":10,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getScriptSnapshot(): cache hit","sequence":80,"time":"2019-01-17T08:52:12.562Z"}
{"context":{"cacheHit":true,"fileName":"/home/hernyo/code/jest-build-error/main/src/__tests__/b.test.ts","logLevel":10,"namespace":"ts-compiler","package":"ts-jest","transformerId":1,"version":"23.10.5"},"message":"getScriptSnapshot(): cache hit","sequence":81,"time":"2019-01-17T08:52:12.562Z"}
```
Minimal repo
https://github.com/hernyo/ts-jest-build-error
Steps to reproduce:
cd localLib
(sudo) npm link
cd ../main
npm install
npm link localLib
npm run clearJest
npm test => success
(sudo) rm -rf node_modules/localLib
cp -r ../localLib node_modules
npm run clearJest
npm test => failure
Top GitHub Comments
Ok, the issue goes away when you include
localLib
in your compilation process by adding it into tsconfig.json:So, the actual issue is the opposite, that jest allows you to compile files that they actually shouldn’t. It works with symlinks, because the resolved path is not inside node_modules so Typescript compiles it again.
We are seeing a similar issue in a lerna monorepo project (“ts-jest”: “24.1.0”) on Mac. The project is written in typescript and some of the project packages import a shared utilities library, also written in typescript The package.json goes something like this:
Running the tests disabling the cache and using the jest configuration like this gave us the same problem:
The workaround we found was to tell jest to map the dependency module (that would be looked up in the node_modules folder of the dependent module) with the actual relative path of the source code of the dependency in our jest.config.js:
This seems to work for us, but it still is a workaround rather than a proper solution.