TypeScript: TS 3.2.1 TypeError: Cannot read property 'kind' of undefined

TypeScript Version: 3.3.0-dev.20181201

Search Terms:

  • “TypeError: Cannot read property ‘kind’ of undefined”
  • “Object.isBinaryExpression”
  • “getTypeReferenceTypeWorker”

Code

Sorry, I need help finding which part of my code is triggering this error. We have a very large code base, and the error does not tell me which file/line/expression is being compiled. Happy to provide more information with assistance.

Expected behavior:

Building through awesome-typescript-loader. Expect compilation and type check to complete without exceptions being thrown.

Actual behavior:

Logs these two error messages (with two different traces).

Sometimes the type check completes and I get all my errors (there are many after the upgrading to 3.2.1). Other times the compile errors are never logged.

On 3.2.1:

  • Sometimes logs just “error 1” during compilation and type checks succeeds.
  • Other times logs both “error 1” and “error 2” during compilation and “error 1” during type check, causing it to fail.

On 3.3.0-dev.20181201:

Only did this once because the build is taking a few minutes on this version (is that normal?).

  • Logged “error 1” and “error 2” during compilation, and “error 1” during type check, causing it to fail.

Error 1:

TypeError: Cannot read property 'kind' of undefined
    at Object.isBinaryExpression (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:13389:21)
    at getTypeReferenceTypeWorker (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:38553:51)
    at getTypeReferenceType (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:38492:24)
    at getTypeFromTypeReference (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:38671:28)
    at getTypeFromTypeNode (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:40178:28)
    at tryGetTypeFromEffectiveTypeNode (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:35562:24)
    at getTypeForVariableLikeDeclaration (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:35192:32)
    at getWidenedTypeForVariableLikeDeclaration (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:35531:56)
    at getTypeOfVariableOrParameterOrPropertyWorker (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:35645:24)
    at getTypeOfVariableOrParameterOrProperty (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:35567:48)
    at getTypeOfSymbol (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:35856:24)
    at checkPropertyAccessExpressionOrQualifiedName (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:48170:53)
    at checkPropertyAccessExpression (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:48122:20)
    at checkExpressionWorker (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:51802:28)
    at checkExpression (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:51745:42)
    at checkTruthinessExpression (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:54156:24)
    at checkBinaryLikeExpression (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:51208:28)
    at checkBinaryExpression (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:51199:20)
    at checkExpressionWorker (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:51841:28)
    at checkExpression (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:51745:42)
    at checkParenthesizedExpression (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:51768:20)
    at checkExpressionWorker (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:51815:28)

Error 2:

TypeError: Cannot read property 'kind' of undefined
    at Object.isBinaryExpression (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:13389:21)
    at getTypeReferenceTypeWorker (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:38576:51)
    at getTypeReferenceType (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:38515:24)
    at getTypeFromTypeReference (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:38694:28)
    at getTypeFromTypeNode (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:40201:28)
    at tryGetTypeFromEffectiveTypeNode (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:35585:24)
    at getTypeForVariableLikeDeclaration (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:35215:32)
    at getWidenedTypeForVariableLikeDeclaration (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:35554:56)
    at getTypeOfVariableOrParameterOrPropertyWorker (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:35668:24)
    at getTypeOfVariableOrParameterOrProperty (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:35590:48)
    at getTypeOfSymbol (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:35879:24)
    at checkPropertyAccessExpressionOrQualifiedName (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:48194:53)
    at checkPropertyAccessExpression (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:48146:20)
    at checkExpressionWorker (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:51826:28)
    at checkExpression (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:51769:42)
    at checkNonNullExpression (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:48120:37)
    at checkPropertyAccessExpressionOrQualifiedName (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:48153:28)
    at checkPropertyAccessExpression (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:48146:20)
    at checkExpressionWorker (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:51826:28)
    at checkExpression (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:51769:42)
    at checkNonNullExpression (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:48120:37)
    at resolveCallExpression (/Users/rhys/Projects/usability-hub/usability_hub/node_modules/typescript/lib/typescript.js:49446:28)

Related Issues:

There are many issues with this error message but with different callstacks. Most are resolved. My understanding is that this error (“Cannot read property ‘kind’ of undefined”) can arise under many circumstances so the others may not be strictly related.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 115
  • Comments: 91 (20 by maintainers)

Commits related to this issue

Most upvoted comments

Getting this on 3.9.3 and 3.9.5.

This error appears on v3.9.2 but not on v3.8.3

I think installing node_module updates solves the issue npm install it worked for me

I use two different loaders depending on environment and noticed happypack works fine, but ts-loader doesn’t.

Temporary workaround:

"postinstall": "sed -i -e 's,export as namespace History;,,' node_modules/@types/history/index.d.ts"

In package.json (scripts) and of course reinstall.

The problem is the line export as namespace History at @types/history/index.d.ts. If this is removed or commented out, no issues appear to arise.

diff --git a/node_modules/@types/history/index.d.ts b/node_modules/@types/history/index.d.ts
index 3fff510..c9aede4 100644
--- a/node_modules/@types/history/index.d.ts
+++ b/node_modules/@types/history/index.d.ts
@@ -3,7 +3,7 @@
 // Definitions by: Sergey Buturlakin <https://github.com/sergey-buturlakin>, Nathan Brown <https://github.com/ngbrown>, Young Rok Kim <https://github.com/rokoroku>
 // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
 // TypeScript Version: 2.3
-export as namespace History;
+// export as namespace History;

 export type Action = 'PUSH' | 'POP' | 'REPLACE';
 export type UnregisterCallback = () => void;

I have the same issue but I generally do restart my server on other port and it automatically fix the issue. 'Strange thing is that it just came the very first time when I start working on my project every day once resolved it won’t be back until I restart my computer. But I’ll try to downgrade the Typescript to 3.1.6 and will let you know.

I got the same error. I use webpack, ts-loader, webpack-dev-middleware.

typescript/lib/typescript.js:13389
        return node.kind === 204 /* BinaryExpression */;
                    ^
TypeError: Cannot read property 'kind' of undefined

I am also seeing this error intermittently compiling with 3.2.1 … This never happens with 3.1.6.

I can confirm the crash, and that it is triggered by line mentioned above in the history library:

export as namespace History;

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/93ed5c28432d50ebcacc9b16f343d2d8be342dc6/types/history/index.d.ts#L6

Manually deleting that line keeps TS from crashing, for my application.

Currently, this issue keeps me locked at TS 3.1, newer versions reproducibly crash, with that line from history (a widely-used library BTW).

Fixed after upgrading to “typescript”: “~3.7.4”

Upgrading to 3.4.1 fixed it for me, without making any other changes.

I simply re-run

ng serve

again and it worked!

Can confirm I was able to resolve this issue by downgrading Typescript to 3.1.6.

Just for the record, here are my versions:

  • Typescript 3.1.6
  • Webpack 4.28.3
  • Webpack-dev-server 3.1.14
  • React-hot-loader 4.6.3

I had the same problem, but with these versions it’s working now:

webpack 4.28.3, webpack-dev-server 3.1.14, react-hot-loader 4.6.3, typescript 3.2.2

I have this problem with those versions ;/

I have exactly the same error when react-hot-loader begins to compile like @wanliyunyan with the same stack on TS 3.2.1 and 3.2.2

also, downgrading to typescript 3.1.6 made no difference for me

We also believe that PR #29339 probably fixes the issue, but have no idea how to write a repro in our test harness - the repro given in this thread needs webpack and a bunch of other moving parts to actually trigger the crash, and it all seems required, but we’re not really sure why - the construct in the checker that causes the crash doesn’t seem to be constructable under normal circumstances.

Fixed it by just adding @types/history

I had this error today in a NodeJS project (not Angular) using TypeScript 3.4.2.

Upgrading to 3.4.5 did not fix the error. Deleting and reinstalling node_modules did not fix the error.

TypeError: Cannot read property 'kind' of undefined                                                                                     
    at Object.getTextOfIdentifierOrLiteral (node_modules\typescript\lib\tsc.js:8418:21)          
    at checkPropertyAccessibility (node_modules\typescript\lib\tsc.js:41021:148)                 
    at checkPropertyAccessExpressionOrQualifiedName (node_modules\typescript\lib\tsc.js:41148:17)
    at checkPropertyAccessExpression (node_modules\typescript\lib\tsc.js:41098:20)               
    at checkExpressionWorker (node_modules\typescript\lib\tsc.js:44383:28)                       
    at checkExpression (node_modules\typescript\lib\tsc.js:44320:38)                             
    at checkBinaryLikeExpression (node_modules\typescript\lib\tsc.js:43770:29)                   
    at checkBinaryExpression (node_modules\typescript\lib\tsc.js:43756:20)                       
    at checkExpressionWorker (node_modules\typescript\lib\tsc.js:44423:28)                       
    at checkExpression (node_modules\typescript\lib\tsc.js:44320:38)                             

Here is the reproduction:

export default abstract class {

  protected abstract get foobar(): string;

  constructor() {
    console.log(this.foobar);
  }
}

Not sure if this is helpful for anyone: For me this line of code was causing the same problem history.pushState(origForm, 'page 2', /Crm/Customers/?${origForm}); I implemented fork-ts-checker-webpack-plugin which also decreased my build time a bit.

I’ve got the same problem. If i use history or window.history in a scope without a variable called history, HMR will crash.

TypeScript version 3.2.2. When back to use v3.1.6, this problem won’t happen.

Here’s my stacktrace:

/Users/pegasusknight/git/monorepo/node_modules/byted-react-scripts/node_modules/typescript/lib/typescript.js:86983
                throw e;
                ^

TypeError: Cannot read property 'kind' of undefined
    at Object.isBinaryExpression (/Users/pegasusknight/git/monorepo/node_modules/byted-react-scripts/node_modules/typescript/lib/typescript.js:13389:21)
    at getTypeReferenceTypeWorker (/Users/pegasusknight/git/monorepo/node_modules/byted-react-scripts/node_modules/typescript/lib/typescript.js:38553:51)
    at getTypeReferenceType (/Users/pegasusknight/git/monorepo/node_modules/byted-react-scripts/node_modules/typescript/lib/typescript.js:38492:24)
    at getTypeFromTypeReference (/Users/pegasusknight/git/monorepo/node_modules/byted-react-scripts/node_modules/typescript/lib/typescript.js:38671:28)
    at getTypeFromTypeNode (/Users/pegasusknight/git/monorepo/node_modules/byted-react-scripts/node_modules/typescript/lib/typescript.js:40178:28)
    at tryGetTypeFromEffectiveTypeNode (/Users/pegasusknight/git/monorepo/node_modules/byted-react-scripts/node_modules/typescript/lib/typescript.js:35562:24)
    at getTypeForVariableLikeDeclaration (/Users/pegasusknight/git/monorepo/node_modules/byted-react-scripts/node_modules/typescript/lib/typescript.js:35192:32)
    at getWidenedTypeForVariableLikeDeclaration (/Users/pegasusknight/git/monorepo/node_modules/byted-react-scripts/node_modules/typescript/lib/typescript.js:35531:56)
    at getTypeOfVariableOrParameterOrPropertyWorker (/Users/pegasusknight/git/monorepo/node_modules/byted-react-scripts/node_modules/typescript/lib/typescript.js:35645:24)
    at getTypeOfVariableOrParameterOrProperty (/Users/pegasusknight/git/monorepo/node_modules/byted-react-scripts/node_modules/typescript/lib/typescript.js:35567:48)

@weswigham @rhys-vdw you could try the error by https://github.com/wanliyunyan/test-typescript-issue-28810, the error occur in my environment at least

  1. npm run dev
  2. modify \src\routes\Home\Index.tsx
  3. compiling…
  4. throw e

I just upgraded typescript for my project and I am seeing this issue again. I upgraded from to 3.6.3 to 3.7.2. Not quite sure how to find the specific offending code, but switching back to 3.6.3 works for now.

This happened to me because i left out the exclude property in webpack config for the awesome-typescript-loader rule.

module: {
    rules: [
      {
        test: /\.(t|j)sx?$/,
        use: { loader: 'awesome-typescript-loader' },
 ### Added exclude for node_modules
        exclude: /node_modules/, 
      },
}

I got this problem caused by @types/history being required by @types/react-router. I removed @types/react-router from my project to get rid of @types/history and it solved it for me. Not ideal, but works for now. Typescript 3.3.1.

It happend to me when I renamed a file name that starts with lowercase, to start with uppercase. While the import statment that loads this file stays on the lowercase version.

The moment I changed the casing in the import statment it got fixed, so it might be related to the OS filesystem case sensitivity. (I’m using windows 10 if that helps)

for me, the issue only occurs with webpack HMR (when using webpack-dev-server). The config scripts are sourced from create-react-app. Here is a stacktrace for reference:

/home/christopher/IdeaProjects/collections-ui/packages/collections-ui-app/node_modules/typescript/lib/typescript.js:86984
                throw e;
                ^

TypeError: Cannot read property 'kind' of undefined
    at Object.isBinaryExpression (/home/christopher/IdeaProjects/collections-ui/packages/collections-ui-app/node_modules/typescript/lib/typescript.js:13389:21)
    at getTypeReferenceTypeWorker (/home/christopher/IdeaProjects/collections-ui/packages/collections-ui-app/node_modules/typescript/lib/typescript.js:38553:51)
    at getTypeReferenceType (/home/christopher/IdeaProjects/collections-ui/packages/collections-ui-app/node_modules/typescript/lib/typescript.js:38492:24)
    at getTypeFromTypeReference (/home/christopher/IdeaProjects/collections-ui/packages/collections-ui-app/node_modules/typescript/lib/typescript.js:38671:28)
    at getTypeFromTypeNode (/home/christopher/IdeaProjects/collections-ui/packages/collections-ui-app/node_modules/typescript/lib/typescript.js:40178:28)
    at tryGetTypeFromEffectiveTypeNode (/home/christopher/IdeaProjects/collections-ui/packages/collections-ui-app/node_modules/typescript/lib/typescript.js:35562:24)
    at getTypeForVariableLikeDeclaration (/home/christopher/IdeaProjects/collections-ui/packages/collections-ui-app/node_modules/typescript/lib/typescript.js:35192:32)
    at getWidenedTypeForVariableLikeDeclaration (/home/christopher/IdeaProjects/collections-ui/packages/collections-ui-app/node_modules/typescript/lib/typescript.js:35531:56)
    at getTypeOfVariableOrParameterOrPropertyWorker (/home/christopher/IdeaProjects/collections-ui/packages/collections-ui-app/node_modules/typescript/lib/typescript.js:35645:24)
    at getTypeOfVariableOrParameterOrProperty (/home/christopher/IdeaProjects/collections-ui/packages/collections-ui-app/node_modules/typescript/lib/typescript.js:35567:48)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! collections-ui-app@0.1.0 start: `node scripts/start.js`

normal tsc compilation works without error. When any file is changed, the above exception is thrown.

we had problem with running local development environment with fuse-box bundler. it did work on ts v3.4.1, but not v3.6.3

thanks to @dmytro-lymarenko hint, in https://github.com/microsoft/TypeScript/issues/28810#issuecomment-628432830 answer, v3.8.3 works like a charm!

At the risk of contributing to a lot of “me too’s” - me too (with 3.9.3)

Sounds like you had a fun time with that one @weswigham. Thanks. 😃

Run into the problem again. Removing export as namespace History; does not fix the error in my case. But I traced down to the error and it turned out to be a problem in @types/history.

@chenyong Maybe you had another copy of @types/history from another dependency? It is a fairly common dependency.

Run into the problem again. Removing export as namespace History; does not fix the error in my case. But I traced down to the error and it turned out to be a problem in @types/history.

function getTypeReferenceTypeWorker(node, symbol, typeArguments) {
            if (symbol.flags & (32 /* Class */ | 64 /* Interface */)) {
                if (symbol.valueDeclaration && symbol.valueDeclaration.parent == null) {

                    console.log(node) // <-------- where I put my log

                }
                if (symbol.valueDeclaration && ts.isBinaryExpression(symbol.valueDeclaration.parent)) {
                    var jsdocType = getJSDocTypeReference(node, symbol, typeArguments);
                    if (jsdocType) {
                        return jsdocType;
                    }
                }
                return getTypeFromClassOrInterfaceReference(node, symbol, typeArguments);
            }
            if (symbol.flags & 524288 /* TypeAlias */) {
                return getTypeFromTypeAliasReference(node, symbol, typeArguments);
            }
            if (symbol.flags & 16 /* Function */ &&
                isJSDocTypeReference(node) &&
                isJSConstructor(symbol.valueDeclaration)) {
                var resolved = resolveStructuredTypeMembers(getTypeOfSymbol(symbol));
                if (resolved.callSignatures.length === 1) {
                    return getReturnTypeOfSignature(resolved.callSignatures[0]);
                }
            }
        }

The output looks messy and I failed to stringify it(circular, but still too large to stringify). Logs is here: https://gist.github.com/chenyong/3ea3c1fe5f07a10ad5e0541727a21001

I confirm that I have to downgrade my Typescript version to 3.1.6 to resolve the problem

i have the same error,when react-hot-loader begin to compile

i 「wdm」: Compiling… ****\node_modules_typescript@3.2.1@typescript\lib\typescript.js:86983 throw e; TypeError: Cannot read property ‘kind’ of undefined at Object.isBinaryExpression (E:\work\sqyypt-portal-h5-web\node_modules_typescript@3.2.1@typescript\lib\typescript.js:13389:21) at getTypeReferenceTypeWorker (E:\work\sqyypt-portal-h5-web\node_modules_typescript@3.2.1@typescript\lib\typescript.js:38553:51) at getTypeReferenceType (E:\work\sqyypt-portal-h5-web\node_modules_typescript@3.2.1@typescript\lib\typescript.js:38492:24) at getTypeFromTypeReference (E:\work\sqyypt-portal-h5-web\node_modules_typescript@3.2.1@typescript\lib\typescript.js:38671:28) at getTypeFromTypeNode (E:\work\sqyypt-portal-h5-web\node_modules_typescript@3.2.1@typescript\lib\typescript.js:40178:28) at tryGetTypeFromEffectiveTypeNode (E:\work\sqyypt-portal-h5-web\node_modules_typescript@3.2.1@typescript\lib\typescript.js:35562:24) at getTypeForVariableLikeDeclaration (E:\work\sqyypt-portal-h5-web\node_modules_typescript@3.2.1@typescript\lib\typescript.js:35192:32) at getWidenedTypeForVariableLikeDeclaration (E:\work\sqyypt-portal-h5-web\node_modules_typescript@3.2.1@typescript\lib\typescript.js:35531:56) at getTypeOfVariableOrParameterOrPropertyWorker (E:\work\sqyypt-portal-h5-web\node_modules_typescript@3.2.1@typescript\lib\typescript.js:35645:24) at getTypeOfVariableOrParameterOrProperty (E:\work\sqyypt-portal-h5-web\node_modules_typescript@3.2.1@typescript\lib\typescript.js:35567:48) at getTypeOfSymbol (E:\work\sqyypt-portal-h5-web\node_modules_typescript@3.2.1@typescript\lib\typescript.js:35856:24) at checkPropertyAccessExpressionOrQualifiedName (E:\work\sqyypt-portal-h5-web\node_modules_typescript@3.2.1@typescript\lib\typescript.js:48170:53) at checkPropertyAccessExpression (E:\work\sqyypt-portal-h5-web\node_modules_typescript@3.2.1@typescript\lib\typescript.js:48122:20) at checkExpressionWorker (E:\work\sqyypt-portal-h5-web\node_modules_typescript@3.2.1@typescript\lib\typescript.js:51802:28) at checkExpression (E:\work\sqyypt-portal-h5-web\node_modules_typescript@3.2.1@typescript\lib\typescript.js:51745:42) at checkNonNullExpression (E:\work\sqyypt-portal-h5-web\node_modules_typescript@3.2.1@typescript\lib\typescript.js:48096:37)