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
- Degrade typescript Degrades ts-dependency from 3.2.2=>3.1.6 due to https://github.com/Microsoft/TypeScript/issues/28810 Exclude /dist in tsconfig.json as it was dramatically slowing down build times — committed to navikt/pleiepengesoknad by erlendev 5 years ago
- :bug: fix web dev server crashing after changes (see https://github.com/Microsoft/TypeScript/issues/28810 ) — committed to Hizoul/polyscript by Hizoul 5 years ago
- Updates TS to 3.4.x This fixes history problem. More info here https://github.com/microsoft/TypeScript/issues/28810. It was fixed here https://github.com/microsoft/TypeScript/pull/29339 with version... — committed to brave/brave-core by NejcZdovc 5 years ago
- Updates TS to 3.4.x This fixes history problem. More info here https://github.com/microsoft/TypeScript/issues/28810. It was fixed here https://github.com/microsoft/TypeScript/pull/29339 with version... — committed to brave/brave-core by NejcZdovc 5 years ago
- Updates TS to 3.4.x This fixes history problem. More info here https://github.com/microsoft/TypeScript/issues/28810. It was fixed here https://github.com/microsoft/TypeScript/pull/29339 with version... — committed to brave/brave-core by NejcZdovc 5 years ago
- Updates TS to 3.4.x This fixes history problem. More info here https://github.com/microsoft/TypeScript/issues/28810. It was fixed here https://github.com/microsoft/TypeScript/pull/29339 with version... — committed to brave/brave-core by NejcZdovc 5 years ago
- Updates TS to 3.4.x This fixes history problem. More info here https://github.com/microsoft/TypeScript/issues/28810. It was fixed here https://github.com/microsoft/TypeScript/pull/29339 with version... — committed to brave/brave-core by NejcZdovc 5 years ago
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:
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.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
.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: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:
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.Here is the reproduction:
I’ve got the same problem. If i use
history
orwindow.history
in a scope without a variable calledhistory
, HMR will crash.TypeScript version 3.2.2. When back to use v3.1.6, this problem won’t happen.
Here’s my stacktrace:
@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
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.
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: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. 😃
@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
.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)