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

TypeScript Version: 3.9.1-rc

Search Terms: typeerror kind

Code

Unknown

Expected behavior:

Compilation

Actual behavior:

TypeError: Cannot read property 'kind' of undefined
    at getErrorSpanForNode (.../node_modules/typescript/lib/typescript.js:13845:22)
    at createDiagnosticForNodeInSourceFile (.../node_modules/typescript/lib/typescript.js:13794:20)
    at Object.createDiagnosticForNode (.../node_modules/typescript/lib/typescript.js:13785:16)
    at .../node_modules/typescript/lib/typescript.js:41784:135
    at Map.forEach (<anonymous>)
    at getInitializerTypeFromAssignmentDeclaration (.../node_modules/typescript/lib/typescript.js:41766:52)
    at getWidenedTypeForAssignmentDeclaration (.../node_modules/typescript/lib/typescript.js:41660:123)
    at getTypeOfFuncClassEnumModuleWorker (.../node_modules/typescript/lib/typescript.js:42220:34)
    at getTypeOfFuncClassEnumModule (.../node_modules/typescript/lib/typescript.js:42199:51)
    at getTypeOfSymbol (.../node_modules/typescript/lib/typescript.js:42312:24)

Playground Link:

Unknown

Related Issues:

Unknown

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 29
  • Comments: 33 (10 by maintainers)

Commits related to this issue

Most upvoted comments

Had the fix been released? I still have the same issue with latest: next 9.4.4, typescript 3.9.5 and ts-node 8.10.2. node -v 12.4.0. The same as was mentioned previously: switching to typescript 3.8.3 fixes the problem.

This is still a problem with TypeScript 3.9.7. @elibarzilay’s repro fails without any modifications. Unfortunately downgrading 3.8.3 is not an option for me because old versions ironically have another bug. Will we get this problem fixed?

I have the problem with typescript 3.9.3 and next 9.4.2 and ts-node 8.10.1. Switching to typescript 3.8.3 fixes the problem.

I see this running typedoc on typescript 4.3.2 too

So, after digging through that pile of s…tuff, here’s an actual minimal repro:

  • x.js:
    module.exports.x = 1;
    module.exports = require("./y.js");
    
  • y.d.ts:
    export declare type x = 1;
    

I seem to have the same issue with next 9.4.2, typescript 3.9.3 and ts-node 8.10.1.

@elibarzilay this happened to me today as I was setting up a new nextjs project. Basically if your checkout this example or yarn create next-app --example custom-server-typescript custom-server-typescript-app and run yarn dev you get this error:

    TypeError: Cannot read property 'kind' of undefined
        at getErrorSpanForNode (../node_modules/typescript/lib/typescript.js:13856:22)
        at createDiagnosticForNodeInSourceFile (../node_modules/typescript/lib/typescript.js:13805:20)
        at Object.createDiagnosticForNode (../node_modules/typescript/lib/typescript.js:13796:16)
        at ../node_modules/typescript/lib/typescript.js:41824:135
        at Map.forEach (<anonymous>)
        at getInitializerTypeFromAssignmentDeclaration (../node_modules/typescript/lib/typescript.js:41806:52)
        at getWidenedTypeForAssignmentDeclaration (../node_modules/typescript/lib/typescript.js:41700:123)
        at getTypeOfFuncClassEnumModuleWorker (../node_modules/typescript/lib/typescript.js:42260:34)
        at getTypeOfFuncClassEnumModule (../node_modules/typescript/lib/typescript.js:42239:51)
        at getTypeOfSymbol (../node_modules/typescript/lib/typescript.js:42352:24)
        at checkPropertyAccessExpressionOrQualifiedName (../node_modules/typescript/lib/typescript.js:57154:53)
        at checkPropertyAccessExpression (../node_modules/typescript/lib/typescript.js:57013:17)
        at checkExpressionWorker (../node_modules/typescript/lib/typescript.js:61646:28)
        at checkExpression (../node_modules/typescript/lib/typescript.js:61567:38)
        at maybeCheckExpression (../node_modules/typescript/lib/typescript.js:60780:34)
        at checkBinaryExpression (../node_modules/typescript/lib/typescript.js:60737:25)

If you pin Typescript to 3.8.3 the error goes away. Cheers

When I switch to Nextjs version 9.4.2, Typescript version 3.9.3, I could no longer see the error

@elibarzilay Hi, Downgrading the TypeScript version from latest to 3.8.3 solves the problem but downgrading TS version is not a good option for me as well. Can we expect a fix for this?

@elibarzilay I opened @SeyedAlirezaFatemi repo in Gitpod and ran these commands:

yarn && yarn build && yarn start

After opening http://localhost:3000 with preview button in Open Ports tab I get the error.

@Hyokune @SeyedAlirezaFatemi @anthanh can you please provide concrete repro steps (ideally involving just a handful of TS/JS files and a config file)? We’ve tried a bunch of different configurations with the linked repo and haven’t been able to cause the exception to occur.

I reproduced the error in this repo: https://github.com/SeyedAlirezaFatemi/ts-error Started from https://github.com/vercel/next.js/tree/canary/examples/custom-server-typescript. build and start and you will see the error.

Same thing here, @SurjitSahoo . Previously it was working fine, but now throws that error. Did you find out a solution? NOTE: My package.json got updated to TS 4.2.4 (cause the ^) and thus the error (some issue with that version I guess…). Editing TS to 4.2 it seems to work fine now.

@sourabh8003 IIRC, it was only included in 4.0.

Sorry, I should have read more carefully. It’s working on 4.0.0-dev.20200729. Thank you.