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鈥檒l 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 · 44 comments
Closed

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

pburkindine opened this issue Apr 5, 2020 · 44 comments

Comments

@pburkindine
Copy link

@pburkindine pburkindine commented Apr 5, 2020

馃悰 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
@ahnpnl
Copy link
Collaborator

@ahnpnl 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.

@pburkindine
Copy link
Author

@pburkindine pburkindine commented Apr 5, 2020

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 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 ahnpnl commented Apr 5, 2020

does clear jest cache and rerun help ?

@pburkindine
Copy link
Author

@pburkindine pburkindine commented Apr 5, 2020

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 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 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 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

@rav2040
Copy link

@rav2040 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

@pburkindine pburkindine commented Apr 6, 2020

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

@ahnpnl
Copy link
Collaborator

@ahnpnl ahnpnl commented Apr 6, 2020

thank you guys, will open a PR for it.

@CamiloGarciaLaRotta
Copy link

@CamiloGarciaLaRotta 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 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 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'

@ahnpnl
Copy link
Collaborator

@ahnpnl ahnpnl commented Jul 23, 2020

would you please provide a reproduce scenario ?

@dwjohnston
Copy link

@dwjohnston dwjohnston commented Jul 23, 2020

Here you go:

https://github.com/dwjohnston/ts-jest-file-repro

I'm macOS 10.15.5.

I'll jump on to my other computer, see if it's happening there.

@ahnpnl
Copy link
Collaborator

@ahnpnl ahnpnl commented Jul 23, 2020

freshly clone, install dependencies and run tests with my Mac. I couldn't see the issue. Do you have specific steps which you did to see the error ?

@dwjohnston
Copy link

@dwjohnston dwjohnston commented Jul 23, 2020

Hmmmm, fresh clone for me isn't producing it either. :(

@ahnpnl
Copy link
Collaborator

@ahnpnl ahnpnl commented Jul 23, 2020

I think something happened to the cache of your previous computer.

@dwjohnston
Copy link

@dwjohnston dwjohnston commented Jul 23, 2020

I'm on the same computer. And that repro was created just by creating a new repo and running install commands. I wonder if VSCode is messing with it?

@dwjohnston
Copy link

@dwjohnston dwjohnston commented Jul 23, 2020

npm cache clean --force

doesn't seem to solve the issue in the original repo.

@ahnpnl
Copy link
Collaborator

@ahnpnl ahnpnl commented Jul 23, 2020

you need to clear jest cache, not npm cache

@dwjohnston
Copy link

@dwjohnston dwjohnston commented Jul 23, 2020

Yup, clearing the jest cache solves it.

@x87
Copy link

@x87 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 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 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 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 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 magwas commented Jul 24, 2020

I believe this issue should be reopened.

@ahnpnl
Copy link
Collaborator

@ahnpnl 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 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 added a commit that referenced this issue Jul 25, 2020
Close #1506
@ahnpnl
Copy link
Collaborator

@ahnpnl 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

@lmanerich lmanerich commented Jul 25, 2020

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

@ahnpnl
Copy link
Collaborator

@ahnpnl 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

@lmanerich lmanerich commented Jul 27, 2020

no issues for me

@ahnpnl
Copy link
Collaborator

@ahnpnl ahnpnl commented Jul 28, 2020

v26.1.4 is out, I will close this issue

@ahnpnl ahnpnl closed this Jul 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
You can鈥檛 perform that action at this time.