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.
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
Should compile without any errors.
Add any other context about the problem here.
Similar issue in a private codebase: using a custom server and using TypeScript 3.9.2
produces the stacktrace below.
Note that:
9.3.6
with TypeScript 3.9.2
.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
.
10.0.18363.836
9.4.0
, 9.3.6
3.9.2
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)
@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
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
.
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.
Seems it has been fixed (https://github.com/microsoft/TypeScript/pull/38596)
While is available can try using typescript@~3.8.3
The issue is still actual
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
.
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?
@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
Most helpful comment
This problem still persists.
@Timer, why is this issue closed?
Is it being tracked on different issue?