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

ts-jest 26.1.2 - "cannot find source file" #1506

Closed
pburkindine opened this issue Apr 5, 2020 · 47 comments · Fixed by #1507
Closed

ts-jest 26.1.2 - "cannot find source file" #1506

pburkindine opened this issue Apr 5, 2020 · 47 comments · Fixed by #1507

Comments

@pburkindine
Copy link

🐛 Bug Report

When attempting to run jest tests with VSCode debugger in 25.3.1, I keep getting error "cannot find source file" after making seemingly innocuous changes to the spec or tested file. Reverting the changes to the source file allows the tests to run. Reverting to 25.2.1 fixes the error.

System:
    OS: OSX 10.15.4

Npm packages:
    jest: 25.2.7
    ts-jest: 25.3.1
    typescript: 3.8.3
@pburkindine pburkindine added Bug Report Needs Repo Need a minimium repository to reproduce the problem Needs Triage labels Apr 5, 2020
@ahnpnl
Copy link
Collaborator

ahnpnl commented Apr 5, 2020

Would you please provide us the reproduce repo ? The information is very limited so it's very difficult for us to investigate. We need:

  • a repo
  • any useful loggings
  • steps to reproduce

Also please follow the bug report template. Those are the useful information that can help us.

@ahnpnl ahnpnl added 🤷‍♂️ Needs More Info waiting for more information from author of the issue and removed Needs Triage labels Apr 5, 2020
@pburkindine
Copy link
Author

Logs:

libs/features/provider-details/src/lib/services/secondary-nav.service.spec.ts
  ● Test suite failed to run

    Could not find source file: '/Users/pete.burkindine/git/ccxp/ccxp-client/libs/features/provider-details/src/lib/services/secondary-nav.service.spec.ts'.

      at getValidSourceFile (node_modules/typescript/lib/typescript.js:135637:29)
      at Object.getSemanticDiagnostics (node_modules/typescript/lib/typescript.js:135859:36)
      at doTypeChecking (node_modules/ts-jest/dist/compiler/language-service.js:11:35)
      at node_modules/ts-jest/dist/compiler/language-service.js:96:25
          at Array.forEach (<anonymous>)
      at compileFn (node_modules/ts-jest/dist/compiler/language-service.js:94:26)
      at Object.compile (node_modules/ts-jest/dist/compiler/instance.js:90:25)
      at TsJestTransformer.process (node_modules/ts-jest/dist/ts-jest-transformer.js:94:41)

Working on a repro

@pburkindine
Copy link
Author

pburkindine commented Apr 5, 2020

@ahnpnl https://github.com/pburkindine/tsjest-cannot-find-source-file

Just adding foo = 'bar'; to this file produced the error: https://github.com/pburkindine/tsjest-cannot-find-source-file/blob/master/apps/tsjest-cannot-find-source-file/src/app/app.component.ts

(this is the test file: https://github.com/pburkindine/tsjest-cannot-find-source-file/blob/master/apps/tsjest-cannot-find-source-file/src/app/app.component.spec.ts)

After running it the first time and getting the error, I noticed I needed to upgrade jest in the repro to match my environment. After the upgrade, the test passed. Then I changed "foo = 'bar'" to "baz = 'quu'" in the component and ran the test, and it failed again with the log below:

Log:

╰─  cd /Users/pete.burkindine/git/test/tsjest-cannot-find-source-file ; /Users/pete.burkindine/.nvm/versions/node/v12.13.1/bin/node --inspect-brk=31549 node_modules/.bin/jest apps/tsjest-cannot-find-source-file/src/app/app.component.spec.ts --config /Users/pete.burkindine/git/test/tsjest-cannot-find-source-file/.debug/jest.config.js --runInBand --runTestsByPath --detectOpenHandles 
Debugger listening on ws://127.0.0.1:31549/74d796b8-cec8-4a6b-a0d1-610530d66cdb
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
 FAIL  apps/tsjest-cannot-find-source-file/src/app/app.component.spec.ts
  ● Test suite failed to run

    Could not find source file: '/Users/pete.burkindine/git/test/tsjest-cannot-find-source-file/apps/tsjest-cannot-find-source-file/src/app/app.component.spec.ts'.

      at getValidSourceFile (node_modules/typescript/lib/typescript.js:135637:29)
          at Array.forEach (<anonymous>)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        4.482s, estimated 5s
Ran all test suites within paths "apps/tsjest-cannot-find-source-file/src/app/app.component.spec.ts".
Waiting for the debugger to disconnect...
[1]    22054 killed     /Users/pete.burkindine/.nvm/versions/node/v12.13.1/bin/node    --config    

@ahnpnl
Copy link
Collaborator

ahnpnl commented Apr 5, 2020

does clear jest cache and rerun help ?

@pburkindine
Copy link
Author

yes, running jest --clearCache allows the test to pass, but then changing the value again (e.g. to qum = 'quo') causes it to immediately fail again

@ahnpnl
Copy link
Collaborator

ahnpnl commented Apr 5, 2020

oh I think I know, it's related to the fix for #1390 . For some reasons it doesn't work for your case

@rav2040
Copy link

rav2040 commented Apr 6, 2020

I have the same issue with all my typescript projects since the update to 25.3.1. After a successful test run, as soon as I change anything in a source file and run the test again, I get the same error. Reverting the change allows the test to complete.

At the moment, all I can do is keep running jest --clearCache every time I change something, or roll back to a previous version of ts-jest.

I set up an example repo that mimics my project setup if it's of any use:
https://github.com/rav2040/ts-jest-error-could-not-find-source-file

I included a GitHub CI test workflow in the repo. If you look at the workflow logs you'll see the test managed to complete even after I changed the value of 'foo' in the source file.

However, when I do the same thing on my own machine I get the following:

 FAIL  __tests__/index.test.ts
  ● Test suite failed to run

    Could not find source file: '/mnt/f/dev/projects/ts-jest-error-could-not-find-source-file/__tests__/index.test.ts'.

      at getValidSourceFile (node_modules/typescript/lib/typescript.js:135637:29)
          at Array.forEach (<anonymous>)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        1.701s
Ran all test suites.

I also tried cloning the repo to a Digital Ocean droplet and running it there, and I still got the same error.

@ahnpnl
Copy link
Collaborator

ahnpnl commented Apr 6, 2020

thank you guys for the information, will look into it asap. Stay tune :)

Updated: would you guys please test the fix with this tgz file https://drive.google.com/open?id=1QRnkDOIy7BXQdSjcybzveBkmE1uCU8h5

@ahnpnl ahnpnl added 🐛 Bug Confirmed Bug is confirmed and removed 🤷‍♂️ Needs More Info waiting for more information from author of the issue Bug Report Needs Repo Need a minimium repository to reproduce the problem labels Apr 6, 2020
@rav2040
Copy link

rav2040 commented Apr 6, 2020

thank you guys for the information, will look into it asap. Stay tune :)

Updated: would you guys please test the fix with this tgz file https://drive.google.com/open?id=1QRnkDOIy7BXQdSjcybzveBkmE1uCU8h5

It works for me 👍

@pburkindine
Copy link
Author

@ahnpnl yeah, fixes it for me as well, thanks

@ahnpnl
Copy link
Collaborator

ahnpnl commented Apr 6, 2020

thank you guys, will open a PR for it.

@CamiloGarciaLaRotta
Copy link

CamiloGarciaLaRotta commented Apr 10, 2020

👋🏽just hit this same issue in VSCode, I can workaround by running jest --clearCache && jest, so it's not a blocker. I was just wondering about the ETA of a new release

@ahnpnl
Copy link
Collaborator

ahnpnl commented Apr 11, 2020

👋🏽just hit this same issue in VSCode, I can workaround by running jest --clearCache && jest, so it's not a blocker. I was just wondering about the ETA of a new release

cc @kulshekhar

@urumo
Copy link

urumo commented Apr 15, 2020

This bug is still present on version ^25.3.0
The issue is almost the same:
modified source file without modifying the test file and boom
"Could not find source file: '/home/user/project/test/User.test.ts'

@dwjohnston
Copy link

Yup, clearing the jest cache solves it.

@x87
Copy link

x87 commented Jul 23, 2020

Same here with v26.1.3. Jest tries to run deleted spec files.

We have a heavy pipeline with hundreds of tests and clearing Jest cache is not an option as it drastically increases running time. Are there any other options?

@ahnpnl
Copy link
Collaborator

ahnpnl commented Jul 23, 2020

after clearing cache, does it still happen after using for a while ? The problem is because new version cannot reuse the old cache, therefore clear cache is required for 1st run.

@x87
Copy link

x87 commented Jul 23, 2020

first time it happened on v26.1.2. we bumped to v26.1.3 and the issue vanished away to re-appear the next day. If it helps, we have a nightly job that clears and rebuilds Jest cache so I'm 100% sure the issue happened on v26.1.3 with the updated cache.

@ahnpnl
Copy link
Collaborator

ahnpnl commented Jul 23, 2020

it would be nice if you can provide a reproduce scenario. I tested with the 2 repos provided here but the issue doesn't appear.

@magwas
Copy link

magwas commented Jul 24, 2020

Same here with jest and ts-jest versions 26.1.0

Error output:

 FAIL  test/dashboard/DashboardContainer.test.tsx
  ● Test suite failed to run

    Could not find source file: '/build/test/dashboard/DashboardChooserContainer.test.tsx'.

      at getValidSourceFile (node_modules/typescript/lib/typescript.js:139175:29)
      at Object.getSemanticDiagnostics (node_modules/typescript/lib/typescript.js:139398:36)
      at doTypeChecking (node_modules/ts-jest/dist/compiler/language-service.js:93:35)
      at compileFn (node_modules/ts-jest/dist/compiler/language-service.js:263:29)
      at Object.compile (node_modules/ts-jest/dist/compiler/instance.js:38:21)
      at TsJestTransformer.process (node_modules/ts-jest/dist/ts-jest-transformer.js:86:41)

DashboardChooserContainer.test.tsx was not available, as it was renamed to DashboardContainer.test.tsx

Probably you can reproduce the issue by running the tests, then renaming one of the test files.

@magwas
Copy link

magwas commented Jul 24, 2020

I believe this issue should be reopened.

@ahnpnl
Copy link
Collaborator

ahnpnl commented Jul 24, 2020

do you use watch mode or non-watch mode ? Hmm I tried renaming but I don't see the issue either. I might know how to fix it but need reproduce steps that can verify the fix.

I think the steps are:

  • Run test with cleared jest cache
  • Rename the a test file
  • Change something in the one of the imported modules (the modules which the test file imports)
  • Run test again and error will be thrown

@ahnpnl ahnpnl reopened this Jul 24, 2020
@ahnpnl ahnpnl changed the title ts-jest 25.3.1 - "cannot find source file" ts-jest 26.1.3 - "cannot find source file" Jul 24, 2020
@ahnpnl ahnpnl added Regression 💥 and removed 🐛 Bug Confirmed Bug is confirmed labels Jul 24, 2020
@ahnpnl ahnpnl changed the title ts-jest 26.1.3 - "cannot find source file" ts-jest 26.1.2 - "cannot find source file" Jul 24, 2020
@ahnpnl
Copy link
Collaborator

ahnpnl commented Jul 25, 2020

Hi @magwas, @x87, @dwjohnston, @lmanerich, @impulse

v26.1.4-alpha.0 is out with the fix. Would you guys please test it by install ts-jest@next ?

If it works, I will publish a new release and close this issue.

Let me know

@lmanerich
Copy link

@ahnpnl using this version right now, so far so good.
Thank you for your support

@ahnpnl
Copy link
Collaborator

ahnpnl commented Jul 27, 2020

hi, does 26.1.4-alpha.0 solve the issue completely ? If yes, maybe 26.1.4 can be released ?

@lmanerich
Copy link

no issues for me

@ahnpnl
Copy link
Collaborator

ahnpnl commented Jul 28, 2020

v26.1.4 is out, I will close this issue

@ahnpnl ahnpnl closed this as completed Jul 28, 2020
bas-l added a commit to philips-labs/docker-action that referenced this issue Mar 9, 2021
Add test for build args
Update jest and ts-jest to resolve an issue where the test file is missing: kulshekhar/ts-jest#1506
bas-l added a commit to philips-labs/docker-action that referenced this issue Mar 9, 2021
* Add option to add --build-arg's to docker
Add test for build args
Update jest and ts-jest to resolve an issue where the test file is missing: kulshekhar/ts-jest#1506

* Update action, readme, dist and version number
@andyfangaf
Copy link

andyfangaf commented Aug 21, 2021

v26.1.4 is out, I will close this issue

This bug is still present in the latest version, at least with Next.js serverless functions.

@Kulimeya
Copy link

I also use the latest version and had this problem, only in watch mode, the normal tests passed perfectly. After clearing the cache it was fixed.

@cassmtnr
Copy link

cassmtnr commented Apr 6, 2022

Still present, cleaning cache doesn't solve, google drive links in this thread are useless as they can be deleted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet