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

Unable to require .d.ts file on Unix only #1289

Closed
JakeStanger opened this issue Nov 12, 2019 · 18 comments
Closed

Unable to require .d.ts file on Unix only #1289

JakeStanger opened this issue Nov 12, 2019 · 18 comments

Comments

@JakeStanger
Copy link

JakeStanger commented Nov 12, 2019

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.

@shigma
Copy link

shigma commented Dec 15, 2019

confronted with the same issue.

@XertroV
Copy link

XertroV commented Dec 18, 2019

@JakeStanger @shigma - if you haven't fixed / worked around this, setting tsconfig.json/compilerOptions.preserveSymlinks to true fixes for me. (For me it's a repo using lerna, but seems like ts-node + symlinks are the issue, so any npm link type stuff in general)

@JakeStanger
Copy link
Author

Not using lerna or any other package/approach that should be creating symlinks, and this fix does not work for me. I will try and put together a minimal repo at some point soon but I still haven't found the cause exactly...

@dl748
Copy link

dl748 commented Dec 31, 2019

Had this issue too, downgraded jest to 24.8 and it fixes it. There is another issue in the list that has the 24.9 breaking change for this module

@ahnpnl
Copy link
Collaborator

ahnpnl commented Jan 8, 2020

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

@franky47
Copy link

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 preserveSymlinks in each tsconfig.json solved the issue.

@JakeStanger
Copy link
Author

JakeStanger commented Jan 17, 2020

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 type feature will serve as a fix.

@deraw
Copy link

deraw commented Jan 22, 2020

I have this issue as well 😕

@es-lynn
Copy link

es-lynn commented Jan 28, 2020

Same issue

beele pushed a commit to beele/homebridge-unifi-protect-camera-motion that referenced this issue Feb 5, 2020
@timshannon
Copy link

Does anyone have a workaround? tsconfig.json/compilerOptions.preserveSymlinks did not fix it for me.

I'm on Linux, and it seems to occasionally work, but it consistently fails when I'm trying to run my tests on a gitlab ci.

@adriangodong
Copy link

I hit this on Windows, I have symlinks created manually.

@ahnpnl
Copy link
Collaborator

ahnpnl commented 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 ?

@ahnpnl
Copy link
Collaborator

ahnpnl commented Feb 22, 2020

Hi everyone, have you guys tested 25.2.1 for this issue ? Is this issue fixed for you guys ?

@pesimeao
Copy link

@ahnpnl in my case it worked! Thank you!

@timshannon
Copy link

@ahnpnl working now for me as well.

Thanks,

@JakeStanger
Copy link
Author

This for me is causing another bizarre error...

With ts-jest@25.2.1, and Jest 24.9.0 or 25.1.0, ALL tests now throw this:

● Test suite failed to run

    TypeError: build_1.replaceRootDirInPath is not a function

      at ../node_modules/ts-jest/dist/compiler.js:117:54
          at Array.map (<anonymous>)
      at Object.createCompiler (../node_modules/ts-jest/dist/compiler.js:117:14)
      at ConfigSet.get (../node_modules/ts-jest/dist/config/config-set.js:389:31)
      at ConfigSet.tsCompiler (../node_modules/ts-jest/dist/util/memoize.js:43:24)
      at TsJestTransformer.process (../node_modules/ts-jest/dist/ts-jest-transformer.js:101:30)
      at ScriptTransformer.transformSource (../node_modules/@jest/transform/build/ScriptTransformer.js:444:35)
      at ScriptTransformer._transformAndBuildScript (../node_modules/@jest/transform/build/ScriptTransformer.js:522:40)
      at ScriptTransformer.transform (../node_modules/@jest/transform/build/ScriptTransformer.js:560:25)

@ahnpnl
Copy link
Collaborator

ahnpnl commented Feb 26, 2020

probably caused by jest-config isn't there, which is fixed in #1408

@JakeStanger
Copy link
Author

Excellent, installing jest-config seems to have fixed it. The new ts-jest version has also fixed the original issue. Awesome!

I'll close this issue now, thank you everybody.

beele pushed a commit to beele/homebridge-unifi-protect-camera-motion that referenced this issue Sep 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests