Skip to content

Cannot read property 'heritageClauses' of undefined #36273

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
Fsss126 opened this issue Jan 18, 2020 · 1 comment · Fixed by #38508
Closed

Cannot read property 'heritageClauses' of undefined #36273

Fsss126 opened this issue Jan 18, 2020 · 1 comment · Fixed by #38508
Assignees
Labels
Bug A bug in TypeScript

Comments

@Fsss126
Copy link

Fsss126 commented Jan 18, 2020

TypeScript Version: 3.7.5

Code

When I add

import 'whatwg-fetch';

in my project with Webpack and run a command to build it or start watching for changes it fails with error

TypeError: Cannot read property 'heritageClauses' of undefined
    at getClassExtendsHeritageElement (/Users/alex/WebstormProjects/rete-tracker/node_modules/typescript/lib/typescript.js:12354:53)
    at Object.getEffectiveBaseTypeNode (/Users/alex/WebstormProjects/rete-tracker/node_modules/typescript/lib/typescript.js:12342:24)
    at getBaseConstructorTypeOfClass (/Users/alex/WebstormProjects/rete-tracker/node_modules/typescript/lib/typescript.js:40022:35)
    at serializeAsClass (/Users/alex/WebstormProjects/rete-tracker/node_modules/typescript/lib/typescript.js:38029:42)
    at serializeSymbolWorker (/Users/alex/WebstormProjects/rete-tracker/node_modules/typescript/lib/typescript.js:37763:29)
    at serializeSymbol (/Users/alex/WebstormProjects/rete-tracker/node_modules/typescript/lib/typescript.js:37704:38)
    at /Users/alex/WebstormProjects/rete-tracker/node_modules/typescript/lib/typescript.js:37679:25
    at Map.forEach (<anonymous>)
    at visitSymbolTable (/Users/alex/WebstormProjects/rete-tracker/node_modules/typescript/lib/typescript.js:37678:33)
    at symbolTableToDeclarationStatements (/Users/alex/WebstormProjects/rete-tracker/node_modules/typescript/lib/typescript.js:37549:17)
    at /Users/alex/WebstormProjects/rete-tracker/node_modules/typescript/lib/typescript.js:36346:106
    at withContext (/Users/alex/WebstormProjects/rete-tracker/node_modules/typescript/lib/typescript.js:36367:37)
    at Object.symbolTableToDeclarationStatements (/Users/alex/WebstormProjects/rete-tracker/node_modules/typescript/lib/typescript.js:36346:28)
    at Object.getDeclarationStatementsForSourceFile (/Users/alex/WebstormProjects/rete-tracker/node_modules/typescript/lib/typescript.js:64426:60)
    at transformDeclarationsForJS (/Users/alex/WebstormProjects/rete-tracker/node_modules/typescript/lib/typescript.js:88037:35)
    at transformRoot (/Users/alex/WebstormProjects/rete-tracker/node_modules/typescript/lib/typescript.js:88114:57)

But it compiles just fine if add this line later when Webpack is already watching for changes in files.

whatwg-fetch has the following in its package.json:

"main": "./dist/fetch.umd.js",
"module": "./fetch.js",

The problem occurs when the module export picked by default, when I point to the script exported as main with

import 'whatwg-fetch/dist/fetch.umd';

everything works fine.

I have the following tsconfig:

{
  "compilerOptions": {
    "target": "es2018",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "outDir": "dist/core", 
    "noEmitOnError": true,
    "sourceMap": true,
    "baseUrl": "src",
    "strictNullChecks": true,
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "downlevelIteration": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "commonjs",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "typeRoots": [
      "./node_modules/@types",
      "./src/declarations"
    ]
  },
  "include": [
    "src"
  ]
}

Related Issues: #10268

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Feb 6, 2020
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.9.0 milestone Feb 6, 2020
@rbuckton
Copy link
Contributor

rbuckton commented May 8, 2020

I do not yet have a consistent repro for this locally, but at first glance this might be due to inconsistent behavior between Webpack and TypeScript. TypeScript does not yet support "module" exports in package.json, so this could possibly be a conflict between what Webpack resolves for import 'whatwg-fetch' vs what TS resolves. This is by no means a definitive answer, so I will continue to investigate.

edit: sorry, I clicked close by mistake when posting the comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants