TypeScript: [BUG] Error: Debug Failure. Invalid cast. The supplied value [object Object] did not pass the test 'isJsonSourceFile'.

TypeScript Version: 3.2.1

Search Terms:

Code

declare global {
  const React: typeof import("react");
  const ReactDOM: typeof import("react-dom");
}

export {};

Expected behavior:

Actual behavior:

> tsc

/Users/akari/Developer/test/node_modules/typescript/lib/tsc.js:71026
                throw e;
                ^

Error: Debug Failure. Invalid cast. The supplied value [object Object] did not pass the test 'isJsonSourceFile'.
    at Object.cast (/Users/akari/Developer/test/node_modules/typescript/lib/tsc.js:1158:22)
    at getTypeOfVariableOrParameterOrPropertyWorker (/Users/akari/Developer/test/node_modules/typescript/lib/tsc.js:29354:41)
    at getTypeOfVariableOrParameterOrProperty (/Users/akari/Developer/test/node_modules/typescript/lib/tsc.js:29334:48)
    at getTypeOfSymbol (/Users/akari/Developer/test/node_modules/typescript/lib/tsc.js:29603:24)
    at resolveImportSymbolType (/Users/akari/Developer/test/node_modules/typescript/lib/tsc.js:33159:45)
    at getTypeFromImportTypeNode (/Users/akari/Developer/test/node_modules/typescript/lib/tsc.js:33141:25)
    at getTypeFromTypeNode (/Users/akari/Developer/test/node_modules/typescript/lib/tsc.js:33460:28)
    at checkImportType (/Users/akari/Developer/test/node_modules/typescript/lib/tsc.js:43996:13)
    at checkSourceElement (/Users/akari/Developer/test/node_modules/typescript/lib/tsc.js:46921:28)

Playground Link: https://gist.github.com/magic-akari/aa10dfb809268eb4f63d5749d113a93a

Related Issues:

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 21
  • Comments: 24 (9 by maintainers)

Commits related to this issue

Most upvoted comments

I remove "esModuleInterop": true; add "allowSyntheticDefaultImports": true.solved the problem.

I got this issue while using webpack’s dev server (in a project based on create-react-app). It will compile fine initially, but it will then throw this error whenever it attempts to re-compile.

I am still getting the same error in TypeScript 3.2.2 where it should have been fixed.

ERROR in : Error: Debug Failure. Invalid cast. The supplied value [object Object] did not pass the test 'isJsonSourceFile'.
    at Object.cast (/home/myprofile/myproject/node_modules/typescript/lib/typescript.js:1325:22)
    at getTypeOfVariableOrParameterOrPropertyWorker (/home/myprofile/myproject/node_modules/typescript/lib/typescript.js:35591:41)
    at getTypeOfVariableOrParameterOrProperty (/home/myprofile/myproject/node_modules/typescript/lib/typescript.js:35567:48)
    at getTypeOfSymbol (/home/myprofile/myproject/node_modules/typescript/lib/typescript.js:35856:24)
    at checkVariableLikeDeclaration (/home/myprofile/myproject/node_modules/typescript/lib/typescript.js:54043:41)
    at checkVariableDeclaration (/home/myprofile/myproject/node_modules/typescript/lib/typescript.js:54116:20)
    at checkSourceElement (/home/myprofile/myproject/node_modules/typescript/lib/typescript.js:56137:28)
    at Object.forEach (/home/myprofile/myproject/node_modules/typescript/lib/typescript.js:210:30)
    at checkVariableStatement (/home/myprofile/myproject/node_modules/typescript/lib/typescript.js:54126:16)
    at checkSourceElement (/home/myprofile/myproject/node_modules/typescript/lib/typescript.js:56106:28)
    at Object.forEach (/home/myprofile/myproject/node_modules/typescript/lib/typescript.js:210:30)
    at checkSourceFileWorker (/home/myprofile/myproject/node_modules/typescript/lib/typescript.js:56305:20)
    at checkSourceFile (/home/myprofile/myproject/node_modules/typescript/lib/typescript.js:56277:13)
    at getDiagnosticsWorker (/home/myprofile/myproject/node_modules/typescript/lib/typescript.js:56352:17)
    at Object.getDiagnostics (/home/myprofile/myproject/node_modules/typescript/lib/typescript.js:56338:24)
    at /home/myprofile/myproject/node_modules/typescript/lib/typescript.js:87001:85

@weswigham I solved it by downgrading to TypeScript 3.1 (if this makes sense!)

I got this issue while using webpack’s dev server (in a project based on create-react-app). It will compile fine initially, but it will then throw this error whenever it attempts to re-compile.

Can confirm, that’s my issue as well after updating to 3.2.1, although I’m using webpack standalone(no create react app)

Same issue here. The only change I made to a repository is to update 3.1.3 to 3.2.1.

If typescript version is locked to 3.1.6 it will remove the ‘isJsonSourceFile’ error

Same issue, also went from 3.1.3 to 3.2.1. I tried making the change suggested by @li2568261, however our project requires esModuleInterop to build at all.

(It’s a React Redux frontend building with babel-loader, awesome-typescript-loader and through webpack)