Skip to content

Typescript type error when running a configuration similar to custom-server-typescript example #12854

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
collinwu opened this issue May 13, 2020 · 10 comments
Labels
Upstream Related to using Next.js with a third-party dependency. (e.g., React, UI/icon libraries, etc.).

Comments

@collinwu
Copy link

collinwu commented May 13, 2020

Bug report

Describe the bug

After upgrading to Next 9.4, I was having an issue with what seems like Typescript reporting an error in my custom TS server project:

TypeError: Cannot read property 'kind' of undefined

The logging is a bit noisy, but compilation is successful.

To Reproduce

This issue could be reproduced by just running the official nextjs custom-server-typescript example here: https://github.com/zeit/next.js/tree/canary/examples/custom-server-typescript

essentially curl the example, cd into the directory, npm install && npm run dev, visit localhost:3000

Expected behavior

Should compile without any errors.

System information

  • OS: macOS 10.15.4
  • Version of Next.js: 9.4.0
  • Version of Node.js: 10.16.3

Additional context

Add any other context about the problem here.

@dandrei
Copy link

dandrei commented May 14, 2020

Similar issue in a private codebase: using a custom server and using TypeScript 3.9.2 produces the stacktrace below.

Note that:

  • the error is also present when using Next.js 9.3.6 with TypeScript 3.9.2.
  • the error is not present when using Next.js 9.4.0 with TypeScript 3.8.3.

For me, it's the TypeScript upgrade to 3.9.2 that breaks all the latest Next.js releases, not a problem specific to Next.js 9.4.0.

  • OS: Windows: 10.0.18363.836
  • Version of Next.js: 9.4.0, 9.3.6
  • Version of TypeScript: 3.9.2
  • Version of Node.js: 14.2.0
error - TypeError: Cannot read property 'kind' of undefined
    at getErrorSpanForNode (C:\code\node_modules\typescript\lib\typescript.js:13856:22)
    at createDiagnosticForNodeInSourceFile (C:\code\node_modules\typescript\lib\typescript.js:13805:20)
    at Object.createDiagnosticForNode (C:\code\node_modules\typescript\lib\typescript.js:13796:16)
    at C:\code\node_modules\typescript\lib\typescript.js:41824:135
    at Map.forEach (<anonymous>)
    at getInitializerTypeFromAssignmentDeclaration (C:\code\node_modules\typescript\lib\typescript.js:41806:52)
    at getWidenedTypeForAssignmentDeclaration (C:\code\node_modules\typescript\lib\typescript.js:41700:123)
    at getTypeOfFuncClassEnumModuleWorker (C:\code\node_modules\typescript\lib\typescript.js:42260:34)
    at getTypeOfFuncClassEnumModule (C:\code\node_modules\typescript\lib\typescript.js:42239:51)
    at getTypeOfSymbol (C:\code\node_modules\typescript\lib\typescript.js:42352:24)
    at checkPropertyAccessExpressionOrQualifiedName (C:\code\node_modules\typescript\lib\typescript.js:57154:53)
    at checkPropertyAccessExpression (C:\code\node_modules\typescript\lib\typescript.js:57013:17)
    at checkExpressionWorker (C:\code\node_modules\typescript\lib\typescript.js:61646:28)
    at checkExpression (C:\code\node_modules\typescript\lib\typescript.js:61567:38)
    at maybeCheckExpression (C:\code\node_modules\typescript\lib\typescript.js:60780:34)
    at checkBinaryExpression (C:\code\node_modules\typescript\lib\typescript.js:60737:25)
    at checkExpressionWorker (C:\code\node_modules\typescript\lib\typescript.js:61687:28)
    at checkExpression (C:\code\node_modules\typescript\lib\typescript.js:61567:38)
    at checkExpressionStatement (C:\code\node_modules\typescript\lib\typescript.js:64036:13)
    at checkSourceElementWorker (C:\code\node_modules\typescript\lib\typescript.js:66564:28)
    at checkSourceElement (C:\code\node_modules\typescript\lib\typescript.js:66442:17)
    at Object.forEach (C:\code\node_modules\typescript\lib\typescript.js:317:30)
    at checkSourceFileWorker (C:\code\node_modules\typescript\lib\typescript.js:66779:20)
    at checkSourceFile (C:\code\node_modules\typescript\lib\typescript.js:66747:13)
    at getDiagnosticsWorker (C:\code\node_modules\typescript\lib\typescript.js:66835:17)
    at getDiagnostics (C:\code\node_modules\typescript\lib\typescript.js:66821:24)
    at Object.getEmitResolver (C:\code\node_modules\typescript\lib\typescript.js:35682:13)
    at emitWorker (C:\code\node_modules\typescript\lib\typescript.js:100790:69)

@collinwu
Copy link
Author

@dandrei is right. i affixed the typescript version 3.4.5 in the custom-server-typescript example with next 9.4.0 / latest and builds/compiles fine. But with the caret symbol prefixed by default, npm grabs the latest minor version 3.9.x hence @dandrei 's stack trace

@collinwu collinwu changed the title 9.4 results in type error when running a configuration similar to custom-server-typescript example Typescript type error when running a configuration similar to custom-server-typescript example May 14, 2020
@mrtnbroder
Copy link

mrtnbroder commented May 14, 2020

Running into the same issue in a private project. However, I can't reproduce it always.
Also Next 9.4.0 and Typescript 3.9.2.

@GainorB
Copy link

GainorB commented May 15, 2020

Same here error with Next 9.3.0 and typescript 3.8.2, I tried upgrading TS to 3.9.2 and I still get the error. This didn't start happening until I installed next-i18next and began to configure it.

@krilbert
Copy link

krilbert commented May 17, 2020

Seems it has been fixed (microsoft/TypeScript#38596)
While is available can try using typescript@~3.8.3

@Timer Timer added the Upstream Related to using Next.js with a third-party dependency. (e.g., React, UI/icon libraries, etc.). label May 19, 2020
@Timer Timer closed this as completed May 19, 2020
@apyrkh
Copy link

apyrkh commented May 20, 2020

The issue is still actual

@dandrei
Copy link

dandrei commented May 21, 2020

I confirm that the problem is still present with TS 3.9.3 and Next.js 9.4.2.
Latest working configuration still uses TS 3.8.3.

@dakotaJang
Copy link

This problem still persists.

{
  "dependencies": {
    "next": "9.5.1",
    "typescript": "^3.9.7"
  }
}

@Timer, why is this issue closed?
Is it being tracked on different issue?

@gajet5
Copy link

gajet5 commented Aug 24, 2020

@Timer yeap, still actual

@dakotaJang He closed the problem because the bug does not play on TS version 3.8.3. In the example, this version is strictly spelled out. https://github.com/vercel/next.js/blob/canary/examples/custom-server-typescript/package.json#L21

update: Fixed in TS ^4.0.2

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Upstream Related to using Next.js with a third-party dependency. (e.g., React, UI/icon libraries, etc.).
Projects
None yet
Development

No branches or pull requests

10 participants