ts-jest: Unable to require `.d.ts` file on Unix only
Issue :
Similar but not the same as #950.
Running tests on my TypeScript project, including a TypeScript dependency, succeeds on Windows. It fails on Linux and OSX with the following:
FAIL src/__tests__/storyshots.test.ts
● 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 `Fields.ts`.
at getOutput (../node_modules/ts-jest/dist/compiler.js:163:23)
at Object.compile (../node_modules/ts-jest/dist/compiler.js:185:29)
at TsJestTransformer.process (../node_modules/ts-jest/dist/ts-jest-transformer.js:101:41)
at Object.<anonymous> (../node_modules/@adm/webpart-library/src/Types.ts:1:1)
Fields.ts contains:
- An interface
- A type
- A function
All of which are exported.
Here is my jest.config.json:
{
"preset": "@voitanos/jest-preset-spfx-react16",
"rootDir": "../src",
"reporters": ["default", "jest-junit"],
"coverageReporters": ["cobertura", "html"],
"collectCoverageFrom": ["**/*.{js,jsx,ts,tsx}", "!**/node_modules/**"],
"moduleNameMapper": {
"\\.(css|scss)$": "identity-obj-proxy",
"^resx-strings/en-us.json": "<rootDir>/node_modules/@microsoft/sp-core-library/lib/resx-strings/en-us.json",
"^office-ui-fabric-react/lib/(.*)$": "office-ui-fabric-react/lib-commonjs/$1",
"^@adm/(.*)/lib/(.*)$": "@adm/$1/src/$2",
"^@adm\/([^\/]*)$": "@adm/$1/src",
"telemetry": "identity-obj-proxy",
"PeopleSearchService": "identity-obj-proxy"
},
"transformIgnorePatterns": [
"node_modules/(?!@adm/)"
]
}
Expected behavior :
The test succeeds regardless of operating system.
Debug log:
Minimal repo :
Very sorry but I do not have time to set one of these up right now. I will try and find the time to get a repo set up as soon as I can.
I am using TS 3.5, NodeJS 8.10.0/10.16.x (tried both), Jest 24.9 and ts-jest 24.0.2.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 3
- Comments: 18
Commits related to this issue
- Weird bugs when running tests See: https://github.com/kulshekhar/ts-jest/issues/1289 — committed to beele/homebridge-unifi-protect-camera-motion by deleted user 4 years ago
- Weird bugs when running tests See: https://github.com/kulshekhar/ts-jest/issues/1289 — committed to beele/homebridge-unifi-protect-camera-motion by deleted user 4 years ago
PR #1385 solved something related and it was merged into master. However we are not sure that it will solve this issue. Can anyone please test the latest changes on master against this issue ?
tsconfig.json/compilerOptions.preserveSymlinksfixed for me (I use Mac). Need some helps from community to investigate the solution.@JakeStanger @Shigma - if you haven’t fixed / worked around this, setting
tsconfig.json/compilerOptions.preserveSymlinkstotruefixes for me. (For me it’s a repo using lerna, but seems like ts-node + symlinks are the issue, so anynpm linktype stuff in general)Same issue
I had the same issue, in a monorepo managed by yarn workspaces (without lerna), only on CI (Travis CI which uses Ubuntu, no issue on macOS).
Adding
preserveSymlinksin eachtsconfig.jsonsolved the issue.I hit this on Windows, I have symlinks created manually.
Downgrading Jest does not work for me, neither does
preserveSymlinks. I am still no closer to finding the actual cause of the problem.I am wondering if the new TS 3.8
export typefeature will serve as a fix.