Skip to content

TypeError: Cannot read property '239' of undefined #18712

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
ccorcos opened this issue Sep 23, 2017 · 5 comments
Closed

TypeError: Cannot read property '239' of undefined #18712

ccorcos opened this issue Sep 23, 2017 · 5 comments
Assignees
Labels
Bug A bug in TypeScript

Comments

@ccorcos
Copy link

ccorcos commented Sep 23, 2017

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:

@ccorcos
Copy link
Author

ccorcos commented Sep 23, 2017

Hmm. Just found this issue which could be useful: #17982

@ccorcos
Copy link
Author

ccorcos commented Sep 23, 2017

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.

@mhegazy
Copy link
Contributor

mhegazy commented Sep 25, 2017

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

@mhegazy mhegazy added the Bug A bug in TypeScript label Sep 25, 2017
@mhegazy mhegazy added this to the TypeScript 2.6 milestone Sep 25, 2017
@ccorcos
Copy link
Author

ccorcos commented Sep 25, 2017

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 ccorcos closed this as completed Sep 25, 2017
@weswigham
Copy link
Member

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

@weswigham weswigham reopened this Sep 25, 2017
weswigham added a commit to weswigham/TypeScript that referenced this issue Sep 25, 2017
weswigham added a commit that referenced this issue Sep 25, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants