Typescript: TypeError: Cannot read property '239' of undefined

Created on 23 Sep 2017  ·  5Comments  ·  Source: microsoft/TypeScript

TypeScript Version: 2.5.2 / nightly (2.5.0-dev.201xxxxx)

Code

I'm upgrading my 2.3 project to 2.5 and I'm getting this really cryptic error:

❯❯❯ ./node_modules/.bin/tsc --noEmit
/Users/chet/Code/notion-next/node_modules/typescript/lib/tsc.js:56136
                throw e;
                ^

TypeError: Cannot read property '239' of undefined
    at getDeclarationSpaces (/Users/chet/Code/notion-next/node_modules/typescript/lib/tsc.js:33091:52)
    at checkExportsOnMergedDeclarations (/Users/chet/Code/notion-next/node_modules/typescript/lib/tsc.js:33037:41)
    at checkInterfaceDeclaration (/Users/chet/Code/notion-next/node_modules/typescript/lib/tsc.js:34730:17)
    at checkSourceElement (/Users/chet/Code/notion-next/node_modules/typescript/lib/tsc.js:35469:28)
    at Object.forEach (/Users/chet/Code/notion-next/node_modules/typescript/lib/tsc.js:275:30)
    at checkSourceFileWorker (/Users/chet/Code/notion-next/node_modules/typescript/lib/tsc.js:35536:20)
    at checkSourceFile (/Users/chet/Code/notion-next/node_modules/typescript/lib/tsc.js:35521:13)
    at getDiagnosticsWorker (/Users/chet/Code/notion-next/node_modules/typescript/lib/tsc.js:35574:17)
    at Object.getDiagnostics (/Users/chet/Code/notion-next/node_modules/typescript/lib/tsc.js:35563:24)
    at /Users/chet/Code/notion-next/node_modules/typescript/lib/tsc.js:56151:85
    at runWithCancellationToken (/Users/chet/Code/notion-next/node_modules/typescript/lib/tsc.js:56129:24)
    at getSemanticDiagnosticsForFileNoCache (/Users/chet/Code/notion-next/node_modules/typescript/lib/tsc.js:56143:20)
    at getAndCacheDiagnostics (/Users/chet/Code/notion-next/node_modules/typescript/lib/tsc.js:56351:26)
    at getSemanticDiagnosticsForFile (/Users/chet/Code/notion-next/node_modules/typescript/lib/tsc.js:56140:20)
    at /Users/chet/Code/notion-next/node_modules/typescript/lib/tsc.js:56097:24
    at Object.flatMap (/Users/chet/Code/notion-next/node_modules/typescript/lib/tsc.js:507:25)
    at getDiagnosticsHelper (/Users/chet/Code/notion-next/node_modules/typescript/lib/tsc.js:56093:56)
    at Object.getSemanticDiagnostics (/Users/chet/Code/notion-next/node_modules/typescript/lib/tsc.js:56104:20)
    at compileProgram (/Users/chet/Code/notion-next/node_modules/typescript/lib/tsc.js:59094:43)
    at compile (/Users/chet/Code/notion-next/node_modules/typescript/lib/tsc.js:59051:26)
    at performCompilation (/Users/chet/Code/notion-next/node_modules/typescript/lib/tsc.js:58940:33)
    at Object.executeCommandLine (/Users/chet/Code/notion-next/node_modules/typescript/lib/tsc.js:58883:9)
    at Object.<anonymous> (/Users/chet/Code/notion-next/node_modules/typescript/lib/tsc.js:59241:4)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/chet/Code/notion-next/node_modules/typescript/bin/tsc:2:1)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:427:7)
    at startup (bootstrap_node.js:151:9)
    at bootstrap_node.js:542:3

Expected behavior:

I would expect an error that tells me something about how I can fix this...

Actual behavior:

Bug

Most helpful comment

This helped! I had the debugger stop on uncaught exception and found that the error was defining a type with the same name as an import.

❯❯❯ node --inspect --debug-brk node_modules/.bin/tsc -p .

It would be nice if this was reported to the user.

All 5 comments

Hmm. Just found this issue which could be useful: https://github.com/Microsoft/TypeScript/issues/17982

This helped! I had the debugger stop on uncaught exception and found that the error was defining a type with the same name as an import.

❯❯❯ node --inspect --debug-brk node_modules/.bin/tsc -p .

It would be nice if this was reported to the user.

@ccorcos can you share a simple repro with the issue?

Hmm. I spent a solid 30 minutes this morning and I'm unable to come up with something minimal :/

In my circumstance, it had to do with an import and an interface having a name collision. There was a lot of JSX in that file and the name collision was for a component. But I'm unable to reproduce it in a minimal example... I guess we'll just hope someone else runs into this and finds this issue.

@ccorcos Don't worry my man, I have a repro for you:

// @filename: b.ts
export const zzz = 123;
export default zzz;

// @filename: a.ts
export interface zzz {
    x: string;
}

import zzz from "./b";

const x: zzz = { x: "" };
zzz;

export default zzz;

// @filename: index.ts
import zzz from "./a";

const x: zzz = { x: "" };
zzz;

import originalZZZ from "./b";
originalZZZ;

const y: originalZZZ = x;

And a fix forthcoming.

Was this page helpful?
0 / 5 - 0 ratings