Closed cefn closed 3 years ago
This issue arises from a circularity which I thought I'd checked for.
It wasn't initially reported by my running of madge with the --ts-config
argument omitted...
cefn@penguin:~/Documents/github/cvnext$ npx madge --circular --extensions ts,tsx ./
Processed 18 files (1.8s) (11 warnings)
ā No circular dependency found!
...or where the --ts-config
argument pointed to the jest-specific tsconfig (which imports the top level one)
cefn@penguin:~/Documents/github/cvnext$ npx madge --circular --ts-config tsconfig.jest.json --extensions ts,tsx ./
Processed 18 files (1.8s) (11 warnings)
ā No circular dependency found!
However, if I point to the top level tsconfig.json
the circularity is revealed.
cefn@penguin:~/Documents/github/cvnext$ npx madge --circular --ts-config tsconfig.json --extensions ts,tsx ./
Processed 18 files (2.2s)
ā Found 1 circular dependency!
1) src/components/index.ts > src/components/Controls.tsx > src/components/controls/Buttons.tsx > src/logic.ts > src/util.tsx
I am not 100% sure why tsc
can handle this circularity without errors, while babel-jest can't. However, the issue is resolved and having circularity here should be avoided anyway.
Thanks to https://stackoverflow.com/questions/67825205/is-this-transpilation-issue-correctly-filed-against-babel-jest/67825887#67825887 for manually identifying this circularity which I hadn't spotted.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.
š Bug Report
I found in a complex Next Typescript project that adding a handful of lines in one file was enough to break transpilation and create runtime errors in a completely different file.
In commit 04c4c7b, I am able to run
yarn
thenyarn run test
and get passing tests. The passing source tree is at https://github.com/cefn/jest-transpile-failure-repro/tree/04c4c7b7013e8b88c25d3ab2a7d4a33ccd3fb191However, after adding the handful of lines which you can see in commit 25703fc the transpiler seems to effectively break and a totally unrelated file starts to get runtime errors during the test which make no sense like...
This error makes no sense because SCORERS is a const defined in the module closure immediately above the function definition here.
It is also a completely unrelated file to those changed in commit 25703fc, suggesting that something about the language constructs in commit
25703fc
has pushed the transpiler into an errored state.Finally it's a runtime error in a file which is already used and runs fine in the production case, so I don't believe there are actually any typescript errors in it.
Recreating the production error
Sorry I wasn't able to reduce the overall complexity of the case (I think that's maybe part of the conditions needed to create the error). To try and clarify the problem I layered in features of my app into a reference Next+Typescript configuration without changing any of the reference babel-jest config until one of the source lines recreated the failure. In that way I've narrowed it down to the handful of lines in the commit described above which are enough to trigger the case.
The repro is based on the canonical reference repo for babel-jest with next and typescript from https://github.com/vercel/next.js/tree/master/examples/with-typescript-eslint-jest
I believe the reference repo relies on babel-jest to transpile Jest tests.
To Reproduce
Check out the repro repository https://github.com/cefn/jest-transpile-failure-repro, run
yarn
thenyarn run test
. If you check out 25703fc7 it will error, and if you then checkout HEAD^1 to go back one commit it passesExpected behavior
Given the imported and tested source code already compiles with
tsc --noEmit
and even runs in production, I would expect it to also run without symbol resolution errors after babel-jest transpilation and importing into a jest test.Link to repl or repo (highly encouraged)
See links in step-by-step above.
envinfo