Skip to content

TypeError: Cannot read property 'kind' of undefined #38383

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

Closed
Jessidhia opened this issue May 7, 2020 · 33 comments · Fixed by #38936
Closed

TypeError: Cannot read property 'kind' of undefined #38383

Jessidhia opened this issue May 7, 2020 · 33 comments · Fixed by #38936
Assignees
Labels
Bug A bug in TypeScript

Comments

@Jessidhia
Copy link

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

@Jessidhia
Copy link
Author

Jessidhia commented May 7, 2020

Adding a console.log to createDiagnosticForNode with all its arguments prints the following:

undefined {
  code: 6203,
  category: 3,
  key: '_0_was_also_declared_here_6203',
  message: "'{0}' was also declared here.",
  reportsUnnecessary: undefined,
  elidedInCompatabilityPyramid: undefined
} undefined globals undefined undefined undefined

nitpick: it's spelled "compatibility"

@Jessidhia
Copy link
Author

Jessidhia commented May 7, 2020

It looks like the line that is causing the crash itself is:

// @ts-check
// this is a jest.config.js file

const config = makeConfig(/* ... */)

config.globals.__STORYBOOK__ = false // this line
// commenting it out prevents the crash

module.exports = config

where the return type of makeConfig is import('@jest/types').Config.InitialOptions.

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label May 8, 2020
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.0 milestone May 8, 2020
@Multiply
Copy link

We're seeing a similar issue, however, I can't seem to find the cause in our code.

@Jessidhia did you add more console.log's in other parts to find the file/line?

@lukaskl
Copy link

lukaskl commented May 13, 2020

I've noticed quite similar (also, looking from stack trace - seemingly different one) issue. I thought that I will better file it as a dedicated issue - #38558. If it will turn out, that it is a duplicate, we can simply close the issue.

@elibarzilay
Copy link
Contributor

@Jessidhia, can you post a precise repro? I tried a few things with the above snippet but can't get it to happen.

@elibarzilay elibarzilay added the Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature label May 18, 2020
@pferdone
Copy link

@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

@elibarzilay
Copy link
Contributor

I'm not sure if I'm doing it right, but I tried the following two chunks in an empty directory:

$ git clone https://github.com/zeit/next.js
$ cd next.js/examples/custom-server-typescript
$ npm i
$ tsc

and

$ yarn create next-app --example custom-server-typescript custom-server-typescript-app
$ cd custom-server-typescript-app
$ yarn dev

Both ran without any errors...

@Multiply
Copy link

@elibarzilay try to change the typescript version to the latest in package.json before installing.

@pferdone
Copy link

pferdone commented May 20, 2020

@elibarzilay @Multiply yeah, it installs Typescript 3.9.3 when I setup the project. I get the error described above and as I said when I switch to 3.8.3 the error goes away.

@elibarzilay
Copy link
Contributor

I'm using a tsc which is wired to a build from the current master, but just in case, I repeated both of the above after editing package.json and removed the TS line, and repeated with editing it to 3.9.3.

Still no errors...

@elibarzilay
Copy link
Contributor

To make this more controllable, I used docker. This is my build file (which doesn't get any errors):

FROM ubuntu

RUN apt update \
 && apt upgrade -y \
 && apt install -y curl

RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - \
 && apt install -y nodejs

RUN curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
 && echo "deb https://dl.yarnpkg.com/debian/ stable main" >> /etc/apt/sources.list \
 && apt update && apt install -y yarn

RUN mkdir /work
WORKDIR /work

RUN yarn create next-app --example custom-server-typescript t \
 && cd t \
 && sed -i -e 's/\("typescript": "^\)\(.*\)"/\13.9.3"/' package.json

@YaoChing
Copy link

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

@Multiply
Copy link

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

Can confirm 9.4.2 of nextjs fixed it for us as well.

@elibarzilay
Copy link
Contributor

I changed the docker setup to change the nextjs version to 9.4.1 and to 9.4.0, and still no error...

@SeyedAlirezaFatemi
Copy link

SeyedAlirezaFatemi commented May 24, 2020

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.

@Hyokune
Copy link

Hyokune commented May 25, 2020

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

@anthanh
Copy link

anthanh commented May 29, 2020

@RyanCavanaugh RyanCavanaugh added Needs More Info The issue still hasn't been fully clarified and removed Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature labels Jun 2, 2020
@RyanCavanaugh
Copy link
Member

@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.

@SeyedAlirezaFatemi
Copy link

@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.

@elibarzilay
Copy link
Contributor

(@RyanCavanaugh, FWIW, I tried this one too, and still no failures.)

@ali4heydari
Copy link

@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.

@elibarzilay
Copy link
Contributor

Ah, I never tried yarn start before -- I now see the crash, finally...

@elibarzilay
Copy link
Contributor

elibarzilay commented Jun 3, 2020

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;
    

@elibarzilay elibarzilay removed the Needs More Info The issue still hasn't been fully clarified label Jun 4, 2020
elibarzilay added a commit to elibarzilay/TypeScript that referenced this issue Jun 4, 2020
elibarzilay added a commit that referenced this issue Jun 4, 2020
@Multiply
Copy link

Bit late with the response, sorry.
After applying your patch locally the issue went away for us. (eagerly waiting for it to be included in a release)

@CherIgor
Copy link

CherIgor commented Jun 19, 2020

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.

@purplesyringa
Copy link

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?

@sourabh8003
Copy link

sourabh8003 commented Jul 26, 2020

@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?

@henhen724
Copy link

Having the same issue with nextJS version 9.4.4 with Typescript version 3.9.7.

@elibarzilay
Copy link
Contributor

@sourabh8003 IIRC, it was only included in 4.0.

@henhen724
Copy link

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

@SurjitSahoo
Copy link

I am still having this issue on node 14.17.0, typescript 4.2.4, ts-node 9.0.0

TypeDoc exiting with unexpected error:
TypeError: Cannot read property 'kind' of undefined
    at Object.isDeclaration (/home/surjit/practice/ds_algo/DataStructures-Algorithms/node_modules/typescript/lib/typescript.js:13449:18)
    at Object.isDeclarationName (/home/surjit/practice/ds_algo/DataStructures-Algorithms/node_modules/typescript/lib/typescript.js:16414:75)
    at getTypeOfSymbolAtLocation (/home/surjit/practice/ds_algo/DataStructures-Algorithms/node_modules/typescript/lib/typescript.js:66938:20)
    at Object.getTypeOfSymbolAtLocation (/home/surjit/practice/ds_algo/DataStructures-Algorithms/node_modules/typescript/lib/typescript.js:45176:35)
    at Object.convertProperty (/home/surjit/practice/ds_algo/DataStructures-Algorithms/node_modules/typedoc/dist/lib/converter/symbols.js:330:176)
    at convertSymbol (/home/surjit/practice/ds_algo/DataStructures-Algorithms/node_modules/typedoc/dist/lib/converter/symbols.js:80:79)
    at convertSymbols (/home/surjit/practice/ds_algo/DataStructures-Algorithms/node_modules/typedoc/dist/lib/converter/symbols.js:86:9)
    at Object.convertClassOrInterface (/home/surjit/practice/ds_algo/DataStructures-Algorithms/node_modules/typedoc/dist/lib/converter/symbols.js:264:5)
    at Object.convertSymbol (/home/surjit/practice/ds_algo/DataStructures-Algorithms/node_modules/typedoc/dist/lib/converter/symbols.js:80:79)
    at Converter.convertExports (/home/surjit/practice/ds_algo/DataStructures-Algorithms/node_modules/typedoc/dist/lib/converter/converter.js:182:23)
npm ERR! code ELIFECYCLE
npm ERR! errno 5
npm ERR! [email protected] docs: `typedoc --options tsdoc.json --plugin typedoc-plugin-extras --favicon docs/favicon.png`
npm ERR! Exit status 5
npm ERR! 
npm ERR! Failed at the [email protected] docs script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

@hadnet
Copy link

hadnet commented May 31, 2021

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.

@Nokel81
Copy link

Nokel81 commented Jun 2, 2021

I see this running typedoc on typescript 4.3.2 too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.