Typescript: tsc crashes with: Cannot read property 'get' of undefined

Created on 21 Feb 2020  ·  1Comment  ·  Source: microsoft/TypeScript

TypeScript Version:
3.2.1 through 3.8.2

Search Terms:
Cannot read property 'get' of undefined

Code

Run these bash commands to create a failing program:

yarn init -y
yarn add typescript@=3.8.2 @types/angular@=1.6.57 @types/angular-mocks@=1.7.0 @types/react@=16.9.21
echo "import { mock } from 'angular';" > test.tsx
echo "const jsx = <h1>jsx</h1>;" >> test.tsx
npx tsc --jsx preserve --lib es2015,dom test.tsx

test.tsx:

import { mock } from 'angular';
const jsx = <h1>jsx</h1>;

To reproduce this, it's important to have all the listed types installed, even if they are not referenced by code:

  • @types/angular
  • @types/angular-mocks
  • @types/react

Expected behavior:

Type checking should succeed.

Actual behavior:

tsc crashes with an error message:

Cannot read property 'get' of undefined

Somehow this depends on using JSX and import { mock } from 'angular' in a single file.
It seems to work OK if you import * as angular from 'angular' and then destructure const { mock } = angular;

stack:

TypeError: Cannot read property 'get' of undefined
    at resolveExternalModuleSymbol (/Users/cthielen/netflix/spinnaker/tt/node_modules/typescript/lib/tsc.js:30086:71)
    at getExportsOfModuleWorker (/Users/cthielen/netflix/spinnaker/tt/node_modules/typescript/lib/tsc.js:30229:28)
    at getExportsOfModule (/Users/cthielen/netflix/spinnaker/tt/node_modules/typescript/lib/tsc.js:30199:70)
    at getExportsOfSymbol (/Users/cthielen/netflix/spinnaker/tt/node_modules/typescript/lib/tsc.js:30194:39)
    at getCandidateListForSymbol (/Users/cthielen/netflix/spinnaker/tt/node_modules/typescript/lib/tsc.js:30554:38)
    at /Users/cthielen/netflix/spinnaker/tt/node_modules/typescript/lib/tsc.js:30537:41
    at Object.forEachEntry (/Users/cthielen/netflix/spinnaker/tt/node_modules/typescript/lib/tsc.js:9568:26)
    at trySymbolTable (/Users/cthielen/netflix/spinnaker/tt/node_modules/typescript/lib/tsc.js:30529:33)
    at getAccessibleSymbolChainFromSymbolTable (/Users/cthielen/netflix/spinnaker/tt/node_modules/typescript/lib/tsc.js:30512:30)
    at _loop_6 (/Users/cthielen/netflix/spinnaker/tt/node_modules/typescript/lib/tsc.js:30457:34)

checker.ts (from master):

This code explicitly asserts that moduleSymbol.exports should exist, but it is missing.

        function resolveExternalModuleSymbol(moduleSymbol: Symbol, dontResolveAlias?: boolean): Symbol;
        function resolveExternalModuleSymbol(moduleSymbol: Symbol | undefined, dontResolveAlias?: boolean): Symbol | undefined;
        function resolveExternalModuleSymbol(moduleSymbol: Symbol, dontResolveAlias?: boolean): Symbol {
            if (moduleSymbol) {
                const exportEquals = resolveSymbol(moduleSymbol.exports!.get(InternalSymbolName.ExportEquals), dontResolveAlias);
                const exported = getCommonJsExportEquals(getMergedSymbol(exportEquals), getMergedSymbol(moduleSymbol));
                return getMergedSymbol(exported) || moduleSymbol;
            }
            return undefined!;
        }

debugger shows missing exports for the symbol:

Screen Shot 2020-02-21 at 8 58 39 AM

Playground Link:

Cannot reproduce in playground link due to the need to install @types packages.

Related Issues:
I did not find any dupes.

Bug

Most helpful comment

Putting angular and react in the same project you're lucky this is the worst that happened 😅

>All comments

Putting angular and react in the same project you're lucky this is the worst that happened 😅

Was this page helpful?
0 / 5 - 0 ratings