question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to require `.d.ts` file on Unix only

See original GitHub issue

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/)"
  ]
}

(Link to preset)

Expected behavior :

The test succeeds regardless of operating system.

Debug log:

ts-jest.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.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:18

github_iconTop GitHub Comments

8reactions
ahnpnlcommented, Feb 14, 2020

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 ?

6reactions
ahnpnlcommented, Jan 10, 2020

tsconfig.json/compilerOptions.preserveSymlinks fixed for me (I use Mac). Need some helps from community to investigate the solution.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Unable to require `.d.ts` file - Stack Overflow
Solved this problem by having all external modules built with a Rollup in esm format and using them instead.
Read more >
TSConfig Reference - Docs on every TSConfig option
This is useful when you only have a small number of files and don't need to ... files with supported extensions are included...
Read more >
Types and Type Declarations | Manual - Deno
When TypeScript is type checking a file, it only cares about the types for ... not have direct control over, the ability to...
Read more >
find ".ts" but not ".d.ts" - Unix & Linux Stack Exchange
Is there another quick way to filter out .d.ts files from my search results? % find --version find (GNU findutils) 4.7.0-git.
Read more >
Mocha - the fun, simple, flexible JavaScript test framework
only () is disallowed). --forbid-only causes Mocha to fail when an exclusive (“only'd”) test or suite is encountered, and it will ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found