I raised an issue https://github.com/facebook/jest/issues/11504 against the jest project, which I think is responsible for maintaining babel-jest. Transpilation totally fails after adding apparently harmless and error-free code.
However, there are a lot of layers to the transpilation of a Typescript Next project, so I am unsure if this is the correct place to file the issue and matches with the likely source of the failure.
Does this issue seem like it matches with the babel-jest project or should I file it somewhere else?
BUG
I found in a complex Next Typescript project that adding a handful of lines in one file was enough to break babel-jest transpilation and create runtime errors in a completely different file.
In commit 04c4c7b, after checking out the clean project and running yarn
I am able to get passing tests with yarn run test
. The passing source tree is at https://github.com/cefn/jest-transpile-failure-repro/tree/04c4c7b7013e8b88c25d3ab2a7d4a33ccd3fb191
However, after adding the handful of lines which you can see in commit 25703fc the babel-jest transpiler seems to effectively break making tests impossible to run, and a totally unrelated file starts to get runtime errors during the test which make no sense like...
ReferenceError: Cannot access 'SCORERS' before initialization
47 | sortedEntries.sort((a: Immutable<Entry>, b: Immutable<Entry>) => {
48 | for (const scoreName of scorePriority) {
> 49 | const scorer = SCORERS[scoreName]
| ^
50 | const diff = scorer(b) - scorer(a)
51 | if (diff !== 0) {
52 | return diff
at sort (src/util.tsx:49:22)
at Array.sort (<anonymous>)
at sortEntries (src/util.tsx:47:17)
at Object.<anonymous> (src/logic.ts:10:20)
at Object.<anonymous> (src/components/controls/Buttons.tsx:6:1)
at Object.<anonymous> (src/components/Controls.tsx:8:1)
at Object.<anonymous> (src/components/index.ts:1:1)
at Object.<anonymous> (src/util.tsx:6:1)
at Object.<anonymous> (test/util.test.ts:3:1)
Note, commit 25703fc compiles with tsc
and runs perfectly well and seems functional.
This error makes no sense because SCORERS is a const defined in the module closure immediately above the function definition.
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.
Should I pursue this with babel, or with nextjs, or is it correctly a babel-jest problem, or some other project?
Anyone know a workaround for e.g. using a totally different babel system to transpile Typescript nextjs code in case I can prove that babel-jest is at fault here?
By way of 'proof' you can see the code compiled and running in production despite the babel-jest compiler error at https://cefn.com/cv
The image below shows the actual lines changed which pushed the transpiler into error as a screenshot from the github diff of the commit...