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

TypeError: Cannot read property 'fileName' of undefined #21

Open
kkm000 opened this issue Aug 31, 2020 · 4 comments
Open

TypeError: Cannot read property 'fileName' of undefined #21

kkm000 opened this issue Aug 31, 2020 · 4 comments

Comments

@kkm000
Copy link

kkm000 commented Aug 31, 2020

I attempted to use jest-runner-tsc for the first time, and am getting the exception when trying to run the test:

  ● Test suite failed to run

    TypeError: Cannot read property 'fileName' of undefined

      at node_modules/jest-runner-tsc/dist/runTsc.js:79:28
          at Array.filter (<anonymous>)
      at runTsc (node_modules/jest-runner-tsc/dist/runTsc.js:77:106)

The error happens here:

const allDiagnostics = ts
.getPreEmitDiagnostics(program)
.concat(emitResult.diagnostics)
.filter(diagnostic => diagnostic.file.fileName === testPath);

and the diagnostic at this point is:

{
  file: undefined,
  start: undefined,
  length: undefined,
  messageText:
   'Option \'--incremental\' can only be specified using tsconfig, emitting to single file or when option `--tsBuildInfoFile` is specified.',
  category: 1,
  code: 5074,
  reportsUnnecessary: undefined,
  reportsDeprecated: undefined
}

Versions:
node.js v10.18.1
jest v.26.4.2
typescript v4.0.2

LMK please if I should dig any deeper.

@prokopsimek
Copy link

The same issue here.

@tony-ist
Copy link

tony-ist commented Apr 14, 2021

My diagnostic was

{
  file: undefined,
  start: undefined,
  length: undefined,
  code: 6059,
  category: 1,
  messageText: {
    messageText: "File '/.../test/exchange.test.ts' is not under 'rootDir' '/.../src'. 'rootDir' is expected to contain all source files.",
    category: 1,
    code: 6059,
    next: [ [Object] ]
  },
  relatedInformation: undefined
}

Solved by moving test directory inside src dir

@patrick-mcdougle
Copy link

I fixed this by adding

"tsBuildInfoFile": ".tsbuildinfo"

to my tsconfig file.

@matt-oplo
Copy link

matt-oplo commented Mar 28, 2022

I had this issue as well when specifying "incremental": true in tsconfig.json. Removing incremental builds solves the issue.

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

No branches or pull requests

5 participants