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

TS 3.2.1 TypeError: Cannot read property 'kind' of undefined #28810

Closed
rhys-vdw opened this issue Dec 3, 2018 · 91 comments · Fixed by #29339
Closed

TS 3.2.1 TypeError: Cannot read property 'kind' of undefined #28810

rhys-vdw opened this issue Dec 3, 2018 · 91 comments · Fixed by #29339
Labels
API Relates to the public API for TypeScript Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output Needs More Info The issue still hasn't been fully clarified

Comments

@rhys-vdw
Copy link
Contributor

rhys-vdw commented Dec 3, 2018

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.

@j-oliveras
Copy link
Contributor

To search related issues to callstacks is better search the top function in callstack: Object.isBinaryExpression or getTypeReferenceTypeWorker

@rhys-vdw
Copy link
Contributor Author

rhys-vdw commented Dec 4, 2018

Thanks @j-oliveras. Only hits are this issue and one other for the latter which seems unrelated.

@wanliyunyan
Copy link

wanliyunyan commented Dec 4, 2018

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)

@weswigham weswigham added Bug A bug in TypeScript Needs More Info The issue still hasn't been fully clarified API Relates to the public API for TypeScript Needs Investigation This issue needs a team member to investigate its status. Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output labels Dec 4, 2018
@weswigham
Copy link
Member

Do you have an example project which reproduces the issue that we can look at?

@rhys-vdw
Copy link
Contributor Author

rhys-vdw commented Dec 4, 2018

@weswigham is it possible to get more information on which file is being parsed from the error with a compiler setting? I'm happy to look into it, but we have ~1000 TS files in our project, as well as external types. Not quite clear how to start.

@weswigham
Copy link
Member

If you instrument the checkSourceFile function in typescript.js to print node.path on entry, you can at least check what file started the chain of operations that led to the crash (we have nothing builtin for tracking checker crashes or progress in general).

@wanliyunyan
Copy link

@weswigham I spent a day trying to find the cause of this error,but no clue.

  1. There are several projects using typescript@3.2.1 on my development environment, but only one of the projects has the error.
  2. This wrong project will cause this error on some people's development environment, and some people‘s development environment has no error.The code is exactly the same.
    3.I keep deleting the code until this error no longer occurs.Then i revert this deleted code, but the error do not occured. Compiled successfully.
    4.if the wrong project use typescript@3.1.6, This error will not occur.
    5 There is no error when starting the project, i modify the code, and an error will occur when compiling .

I don't know what clues I can provide.

@mdurling
Copy link

mdurling commented Dec 6, 2018

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

@weswigham
Copy link
Member

I think this may be the result of a UMD global merging with a class? Like maybe

// @filename: class.d.ts
class Foo {}
export = Foo;
declare global {
  const Mod: typeof Foo;
}
export as namespace Mod;
// @filename: usage.d.ts
type Foob = Mod;

... maybe? Does anyone know if they've got any export as namespace's going on in their projects, and, if so, if they also have any declare globals of the same? Doesn't explain how it could possibly be intermittent, but...

@mdurling
Copy link

mdurling commented Dec 7, 2018

Our project has a module that exports a function and a namespace with the same name if that fits your scenario. We could make some changes, but that's never been a problem before now.

@weswigham
Copy link
Member

Mmm, not really, not what I was thinking of.

@wanliyunyan
Copy link

wanliyunyan commented Dec 7, 2018

@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

@Q-Man
Copy link

Q-Man commented Dec 10, 2018

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

@jbrownfield
Copy link

I get the same error if I try to use the rest operator to split one object into two objects. I'm not sure if this is even legal as I couldn't find a definitive answer, but I thought I'd try it and see. There's no Error in Webstorm, or on compilation, but on load, I get:

ERROR in : TypeError: Cannot read property 'kind' of undefined at Object.getTextOfPropertyName (/Users/jimbrownfield/radical/Consulting/ComAppTech/node_modules/typescript/lib/typescript.js:8653:22) at getRestType (/Users/jimbrownfield/radical/Consulting/ComAppTech/node_modules/typescript/lib/typescript.js:34290:30) at checkObjectLiteralDestructuringPropertyAssignment (/Users/jimbrownfield/radical/Consulting/ComAppTech/node_modules/typescript/lib/typescript.js:49992:28) at checkObjectLiteralAssignment (/Users/jimbrownfield/radical/Consulting/ComAppTech/node_modules/typescript/lib/typescript.js:49958:17) at checkDestructuringAssignment (/Users/jimbrownfield/radical/Consulting/ComAppTech/node_modules/typescript/lib/typescript.js:50097:24) at checkBinaryLikeExpression (/Users/jimbrownfield/radical/Consulting/ComAppTech/node_modules/typescript/lib/typescript.js:50187:24) at checkBinaryExpression (/Users/jimbrownfield/radical/Consulting/ComAppTech/node_modules/typescript/lib/typescript.js:50182:20) at checkExpressionWorker (/Users/jimbrownfield/radical/Consulting/ComAppTech/node_modules/typescript/lib/typescript.js:50789:28) at checkExpression (/Users/jimbrownfield/radical/Consulting/ComAppTech/node_modules/typescript/lib/typescript.js:50696:42) at checkParenthesizedExpression (/Users/jimbrownfield/radical/Consulting/ComAppTech/node_modules/typescript/lib/typescript.js:50719:20) at checkExpressionWorker (/Users/jimbrownfield/radical/Consulting/ComAppTech/node_modules/typescript/lib/typescript.js:50763:28) at checkExpression (/Users/jimbrownfield/radical/Consulting/ComAppTech/node_modules/typescript/lib/typescript.js:50696:42) at checkExpressionStatement (/Users/jimbrownfield/radical/Consulting/ComAppTech/node_modules/typescript/lib/typescript.js:53068:13) at checkSourceElement (/Users/jimbrownfield/radical/Consulting/ComAppTech/node_modules/typescript/lib/typescript.js:55035:28) at Object.forEach (/Users/jimbrownfield/radical/Consulting/ComAppTech/node_modules/typescript/lib/typescript.js:210:30) at checkBlock (/Users/jimbrownfield/radical/Consulting/ComAppTech/node_modules/typescript/lib/typescript.js:52672:20)

The code line is:

({...this.address, ...this.aniRecordInformation} = value);

If I comment this like out, it compiles and loads.

Totally willing to admit that my code may be illegal, but it should give me a better compile-time error (or at least any compile-time error).

@Connormiha
Copy link

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

@zbuttram
Copy link

Having the same problem here. Usually random but I can get it to happen consistently by switching between two branches in my repo (happens in both directions). I was able to narrow it down to one file by instrumenting part of typescript.js as @weswigham suggested, but I don't see anything in that file that looks suspicious. That said, its not exactly tiny at 480 lines. Any way to narrow down to a line in that file?

@weswigham
Copy link
Member

Instrumenting getTypeReferenceTypeWorker to log the locations of each element of symbol.declarations when symbol.valueDeclaration.parent === undefined is probably what you'd want to look at.

@zbuttram
Copy link

@weswigham Thanks for the tip, but I think I might not be doing something right. I added the following right before the if statement that contains the throwing call to isBinaryExpression:

if (symbol.valueDeclaration && symbol.valueDeclaration.parent === undefined) {
  console.log('symbol.declarations', symbol.declarations);
}

And I'm seeing a huge SourceFileObject that appears to be node_modules/@types/history/index.d.ts, but it appears to crash before console.log finishes printing the whole object.

After further inspection, the file I mentioned in my previous post does use history.pushState in one place. After commenting this out, the compile doesn't crash when switching branches, and instead just shows me a bunch of compile errors related to not picking up some .d.ts files that are present in one branch but not the other or vice versa (not entirely unexpected). I also tried changing the call to window.history.pushState just to see but that still results in the crash.

I'm not really sure what any of that means, but I'm happy to do more testing on my end since I'm able to reproduce it consistently.

@weswigham
Copy link
Member

weswigham commented Dec 20, 2018

Seems like it might be an issue with something in the shape of @types/history. I think it's probably caused by the merge of a class and a source file via a UMD declaration and a global. Once I get an isolated repro (so we don't regress) it should be easy to fix.

@wanliyunyan
Copy link

@weswigham
Copy link
Member

I meant a minimal repro for our regression testing suite. 😄 Still gotta sort thru that one to see what's required to cause the issue.

@wanliyunyan
Copy link

wanliyunyan commented Dec 20, 2018

well, I tried to delete unnecessary files("/src/applyLoan" that is not be imported actually, I think this is the key to the problem.) about the repro, but the error is gone. I don't know how I can help you anymore. @weswigham

@weswigham
Copy link
Member

That's OK. I wasn't asking for anyone specifically to reduce it. Just remarking that it needs doing to make a fix~

@philipp985
Copy link

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.

@christopher-johnson
Copy link

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.

@maksnester
Copy link

maksnester commented Jun 25, 2019

I have this issue while trying to add custom transformers with ts-loader. Tried with the following ts versions:

  • 3.2.4
  • 3.4.1
  • 3.5.2
TypeError: Cannot read property 'kind' of undefined
    at Object.isSourceFile (C:\Users\U\Desktop\Project\node_modules\typescript\lib\typescript.js:14006:2
1)
    at emitShebangIfNeeded (C:\Users\U\Desktop\Project\node_modules\typescript\lib\typescript.js:86038:2
0)
    at Object.writeFile (C:\Users\U\Desktop\Project\node_modules\typescript\lib\typescript.js:83735:13)
    at printSourceFileOrBundle (C:\Users\U\Desktop\Project\node_modules\typescript\lib\typescript.js:832
66:25)
    at emitJsFileOrBundle (C:\Users\U\Desktop\Project\node_modules\typescript\lib\typescript.js:83176:13
)
    at emitSourceFileOrBundle (C:\Users\U\Desktop\Project\node_modules\typescript\lib\typescript.js:8310
8:13)
    at forEachEmittedFile (C:\Users\U\Desktop\Project\node_modules\typescript\lib\typescript.js:82900:34
)
    at Object.emitFiles (C:\Users\U\Desktop\Project\node_modules\typescript\lib\typescript.js:83091:9)
    at emitWorker (C:\Users\U\Desktop\Project\node_modules\typescript\lib\typescript.js:89012:33)
    at C:\Users\U\Desktop\Project\node_modules\typescript\lib\typescript.js:88972:66
    at runWithCancellationToken (C:\Users\U\Desktop\Project\node_modules\typescript\lib\typescript.js:89
063:24)
    at Object.emit (C:\Users\U\Desktop\Project\node_modules\typescript\lib\typescript.js:88972:20)
    at Object.transpileModule (C:\Users\U\Desktop\Project\node_modules\typescript\lib\typescript.js:1081
26:17)
    at getTranspilationEmit (C:\Users\U\Desktop\Project\node_modules\ts-loader\dist\index.js:231:74)
    at successLoader (C:\Users\U\Desktop\Project\node_modules\ts-loader\dist\index.js:33:11)
    at Object.loader (C:\Users\U\Desktop\Project\node_modules\ts-loader\dist\index.js:21:12)

Transformer config is like that:

// webpack.config
const tsLoaderOptions = {
  transpileOnly: true,
  getCustomTransformers: path.join(__dirname, './webpack.ts-transformers.js')
}
// webpack.ts-transformers.js
const optChainTransformer = require('ts-optchain/transform').default
const getCustomTransformers = () => ({ after: [optChainTransformer] })
module.exports = getCustomTransformers

If I change after to before, then I have this error:

Module build failed (from ./node_modules/ts-loader/index.js):
TypeError: Cannot read property 'length' of undefined
    at Object.firstOrUndefined (C:\Users\U\Desktop\Project\node_modules\typescript\lib\typescript.js:108
3:22)
    at Object.startsWithUseStrict (C:\Users\U\Desktop\Project\node_modules\typescript\lib\typescript.js:
64032:33)
    at Object.visitLexicalEnvironment (C:\Users\U\Desktop\Project\node_modules\typescript\lib\typescript
.js:64984:36)
    at visitSourceFile (C:\Users\U\Desktop\Project\node_modules\typescript\lib\typescript.js:67712:53)
    at saveStateAndInvoke (C:\Users\U\Desktop\Project\node_modules\typescript\lib\typescript.js:67355:27
)
    at transformSourceFile (C:\Users\U\Desktop\Project\node_modules\typescript\lib\typescript.js:67338:2
7)
    at transformSourceFileOrBundle (C:\Users\U\Desktop\Project\node_modules\typescript\lib\typescript.js
:67318:20)
    at C:\Users\U\Desktop\Project\node_modules\typescript\lib\typescript.js:1492:86
    at reduceLeft (C:\Users\U\Desktop\Project\node_modules\typescript\lib\typescript.js:1187:30)
    at C:\Users\U\Desktop\Project\node_modules\typescript\lib\typescript.js:1492:42
    at transformRoot (C:\Users\U\Desktop\Project\node_modules\typescript\lib\typescript.js:82675:82)
    at Object.map (C:\Users\U\Desktop\Project\node_modules\typescript\lib\typescript.js:499:29)
    at Object.transformNodes (C:\Users\U\Desktop\Project\node_modules\typescript\lib\typescript.js:82662
:30)
    at emitJsFileOrBundle (C:\Users\U\Desktop\Project\node_modules\typescript\lib\typescript.js:83154:32
)
    at emitSourceFileOrBundle (C:\Users\U\Desktop\Project\node_modules\typescript\lib\typescript.js:8310
8:13)
    at forEachEmittedFile (C:\Users\U\Desktop\Project\node_modules\typescript\lib\typescript.js:82900:34
)

@gaetanlegac
Copy link

gaetanlegac commented Aug 30, 2019

Same error when I try to add a new element via a custom transformer with ts-loader:

import transformateurRepoGraphql from '../serveur/plugins/typescript/repo-graphql';
...
{
    loader: 'ts-loader',
    options: {
        transpileOnly: false,
        configFile: resolvePath('./tsconfig.json'),
        context: ROOT_DIR,
        getCustomTransformers: () => ({
            before: [transformateurRepoGraphql()]
        }),
    }
}
import * as path from 'path';
import * as ts from 'typescript';

export function createTransformer(): ts.TransformerFactory<ts.SourceFile> {
    const transformer: ts.TransformerFactory<ts.SourceFile> = (context) => {
        const { sourceRoot } = context.getCompilerOptions();
        return (file) => {
            const visitor: ts.Visitor = (node) => {
                if (ts.isCallExpression( node )) {

                    node.arguments = [ ts.createObjectLiteral([]) ];

                    return node;
                }
                return ts.visitEachChild(node, visitor, context);
            }
            return ts.visitNode(file, visitor);
        };
    };

    return transformer;
}

export default createTransformer;

I get this error:

TypeError: Cannot read property 'kind' of undefined
    at getAssignmentTargetKind (node_modules/typescript/lib/typescript.js:10688:28)
    at Object.isAssignmentTarget (node_modules/typescript/lib/typescript.js:10731:16)
    at checkArrayLiteral (node_modules/typescript/lib/typescript.js:49045:45)
    at checkExpressionWorker (node_modules/typescript/lib/typescript.js:53941:28)
    at checkExpression (node_modules/typescript/lib/typescript.js:53878:38)
    at checkExpressionWithContextualType (node_modules/typescript/lib/typescript.js:53596:24)
    at checkApplicableSignature (node_modules/typescript/lib/typescript.js:50853:35)
    at chooseOverload (node_modules/typescript/lib/typescript.js:51238:26)
    at resolveCall (node_modules/typescript/lib/typescript.js:51157:26)
    at resolveCallExpression (node_modules/typescript/lib/typescript.js:51468:20)
    at resolveSignature (node_modules/typescript/lib/typescript.js:51759:28)
    at getResolvedSignature (node_modules/typescript/lib/typescript.js:51790:26)
    at checkCallExpression (node_modules/typescript/lib/typescript.js:51877:29)
    at checkExpressionWorker (node_modules/typescript/lib/typescript.js:53956:28)
    at checkExpression (node_modules/typescript/lib/typescript.js:53878:38)
    at checkAwaitExpression (node_modules/typescript/lib/typescript.js:52855:31)

Same with createArrayLiteral([]). When I use createStringLiteral("yo"), I get this one:

TypeError: Cannot read property 'text' of undefined
    at getErrorSpanForNode (node_modules/typescript/lib/typescript.js:9363:40)
    at Object.createDiagnosticForNodeFromMessageChain (node_modules/typescript/lib/typescript.js:9290:20)
    at checkTypeRelatedTo (node_modules/typescript/lib/typescript.js:42751:31)
    at checkTypeRelatedToAndOptionallyElaborate (node_modules/typescript/lib/typescript.js:42030:24)
    at checkApplicableSignature (node_modules/typescript/lib/typescript.js:50858:26)
    at resolveCall (node_modules/typescript/lib/typescript.js:51168:21)
    at resolveCallExpression (node_modules/typescript/lib/typescript.js:51468:20)
    at resolveSignature (node_modules/typescript/lib/typescript.js:51759:28)
    at getResolvedSignature (node_modules/typescript/lib/typescript.js:51790:26)
    at checkCallExpression (node_modules/typescript/lib/typescript.js:51877:29)
    at checkExpressionWorker (node_modules/typescript/lib/typescript.js:53956:28)
    at checkExpression (node_modules/typescript/lib/typescript.js:53878:38)
    at checkAwaitExpression (node_modules/typescript/lib/typescript.js:52855:31)
    at checkExpressionWorker (node_modules/typescript/lib/typescript.js:53980:28)
    at checkExpression (node_modules/typescript/lib/typescript.js:53878:38)
    at checkExpressionCached (node_modules/typescript/lib/typescript.js:53617:38)

Typescript version: 3.5.3

Exactly the same if I change before to after
Temporarily fixed by using awesome-typescript-loader instead of ts-loader
The errors also occurs with at-loader

NejcZdovc added a commit to brave/brave-core that referenced this issue Sep 19, 2019
This fixes history problem. More info here microsoft/TypeScript#28810.

It was fixed here microsoft/TypeScript#29339 with version 3.4.x
NejcZdovc added a commit to brave/brave-core that referenced this issue Sep 19, 2019
This fixes history problem. More info here microsoft/TypeScript#28810.

It was fixed here microsoft/TypeScript#29339 with version 3.4.x
NejcZdovc added a commit to brave/brave-core that referenced this issue Sep 19, 2019
This fixes history problem. More info here microsoft/TypeScript#28810.

It was fixed here microsoft/TypeScript#29339 with version 3.4.x
NejcZdovc added a commit to brave/brave-core that referenced this issue Sep 19, 2019
This fixes history problem. More info here microsoft/TypeScript#28810.

It was fixed here microsoft/TypeScript#29339 with version 3.4.x
NejcZdovc added a commit to brave/brave-core that referenced this issue Sep 19, 2019
This fixes history problem. More info here microsoft/TypeScript#28810.

It was fixed here microsoft/TypeScript#29339 with version 3.4.x
@iamdevlinph
Copy link

iamdevlinph commented Oct 30, 2019

Updated to 3.6.4 and still getting the error.
I only get the error when I use ts-react-display-name

Is there anyway to debug this issue?

@iamdevlinph
Copy link

For my case, my issue was fixed by adding the following code to my tsconfig.json

"awesomeTypescriptLoaderOptions": {
    "useTranspileModule": true
}

@ngmgit
Copy link

ngmgit commented Nov 4, 2019

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/, 
      },
}

@richtera
Copy link

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.

@zdrawku
Copy link

zdrawku commented Dec 23, 2019

Fixed after upgrading to "typescript": "~3.7.4"

@Jack-Works
Copy link
Contributor

3.7.5 or 3.7.4 Not working for me either.

Works on 3.8.0 (nightly)

@Jack-Works
Copy link
Contributor

For anyone who is developing a transformer: if you are using npm link / yarn link, this error may be caused by using a different versions of ts at the same time.

@arvinzzq
Copy link

Hi!, @weswigham , it there any answer about this bug? Local version of typescript of my project is 3.8.3, and ts crush whatever I changed..... It is makes me can not do anything.....

@bmeritter
Copy link

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)

I also have the same error,when angular hot loading

@RajeshGSN
Copy link

Any resolution for this issue ?? its happening with 3.8.3

@willdunlop
Copy link

willdunlop commented Apr 4, 2020

I was receiving this error while using typescript in my react application. In the hopes that it may help some people, I was able to resolve this by removing the defaultProps declaration that I had on my functional component.

type MenuActionProps = {
    id:string;
    menuItems:SubMenuItem[];
    children:string
}

export default function MenuAction(props:MenuActionProps) {
    const [menuAnchorEl, setMenuAnchorEl] = React.useState<null | HTMLElement>(null);
    const classes = useStyles()

    function toggleMenu(e:React.MouseEvent<HTMLElement> | null) {
        if (e && !menuAnchorEl) setMenuAnchorEl(e.currentTarget)
        else setMenuAnchorEl(null)
    }

    return (
        <>
            <button
                className="file-menu__item"
                onClick={toggleMenu}
            >
                {props.children}
            </button>
            <MenuPanel
                id={props.id}
                isHover={false}
                anchorEl={menuAnchorEl}
                menuItems={props.menuItems}
                toggleMenu={toggleMenu}
            />
        </>
    )
}

/** 
 * @Error TypeError: Cannot read property 'kind' of undefined
 * Commenting out the below declaration solved the error. No idea why though
 **/
MenuAction.defaultProps = {
    id: "menu",
    menuItems: [] as SubMenuItem[],
    children: "Menu"
}

My console error stack appeared as the following

ERROR in ./src/components/common/MenuAction.tsx
Module build failed (from ./node_modules/ts-loader/index.js):
TypeError: Cannot read property 'kind' of undefined
    at Object.isFunctionDeclaration (./node_modules/typescript/lib/typescript.js:11435:21)
    at Object.getEffectiveTypeAnnotationNode (./node_modules/typescript/lib/typescript.js:16308:37)
    at getIsContextSensitiveAssignmentOrContextType (./node_modules/typescript/lib/typescript.js:53993:52)
    at getContextualTypeForBinaryOperand (./node_modules/typescript/lib/typescript.js:53941:44)
    at getContextualType (./node_modules/typescript/lib/typescript.js:54288:28)
    at getApparentTypeOfContextualType (./node_modules/typescript/lib/typescript.js:54185:17)
    at checkObjectLiteral (./node_modules/typescript/lib/typescript.js:54704:34)
    at checkExpressionWorker (./node_modules/typescript/lib/typescript.js:60100:28)
    at checkExpression (./node_modules/typescript/lib/typescript.js:60023:38)
    at checkExpressionCached (./node_modules/typescript/lib/typescript.js:59701:38)
 @ ./src/components/HeaderMenu.tsx 11:0-23:2
 @ ./src/components/App.tsx
 @ ./src/index.tsx

Module versions

"typscript": "^3.8.3"
"ts-loader": "^6.2.2"
"react": "^16.13.1",
"react-dom": "^16.13.1"

@dmytro-lymarenko
Copy link

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

@WEN-JY
Copy link

WEN-JY commented May 19, 2020

my error was 'TypeError: Cannot read property 'kind' of undefined at getErrorSpanForNode',and disappeared after downgrade typescript from ^3.9.2 to 3.7.2.

@choopk
Copy link

choopk commented May 24, 2020

my error was 'TypeError: Cannot read property 'kind' of undefined at getErrorSpanForNode',and disappeared after downgrade typescript from ^3.9.2 to 3.7.2.

Yes i have the same issue

@rcoundon
Copy link

rcoundon commented May 24, 2020

At the risk of contributing to a lot of "me too's" - me too (with 3.9.3)

@anthanh
Copy link

anthanh commented May 29, 2020

there is also a related open issue here #38383

@dwxw
Copy link

dwxw commented Jun 11, 2020

Getting this on 3.9.3 and 3.9.5.

@trungdang194
Copy link

I got this error while using typescript 3.9.6, 3.7.5, when enter command ng lint, but run successfully when downgrade to version 3.1.6

@myxit
Copy link

myxit commented Aug 5, 2020

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 #28810 (comment) answer, v3.8.3 works like a charm!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Relates to the public API for TypeScript Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output Needs More Info The issue still hasn't been fully clarified
Projects
None yet
Development

Successfully merging a pull request may close this issue.