Skip to content

TSC Watch crashes when class is exported as module.exports.default in JS file - cannot read property 'kind' of undefined #41101

Description

@myfatemi04

I get this error:

[12:18:51 PM] Starting compilation in watch mode...

C:\Users\legoc\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:84774
                throw e;
                ^

TypeError: Cannot read property 'kind' of undefined
    at Object.isEntityNameExpression (C:\Users\legoc\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:13169:21)
    at serializeMaybeAliasAssignment (C:\Users\legoc\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:39495:42)
    at serializeSymbolWorker (C:\Users\legoc\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:39161:49)
    at serializeSymbol (C:\Users\legoc\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:39126:38)
    at C:\Users\legoc\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:39107:25
    at Map.forEach (<anonymous>)
    at visitSymbolTable (C:\Users\legoc\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:39106:33)
    at serializeAsNamespaceDeclaration (C:\Users\legoc\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:39370:25)
    at serializeAsFunctionNamespaceMerge (C:\Users\legoc\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:39348:25)
    at serializeMaybeAliasAssignment (C:\Users\legoc\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:39525:29)

This happens when I create a file called "index.js" and try to compile it with tsc -w.

Here is my tsconfig.json:

{
  "compilerOptions": {
    "module": "commonjs",
    "outDir": "dist",
    "sourceMap": true,
    "strict": true,
    "target": "es2017",
    "noImplicitAny": false,
    "allowJs": true
  },
  "compileOnSave": true,
  "include": [ "src" ]
}

TSC breaks and doesn't offer a helpful error message.
The following is the code that can be used to reproduce this exact error.
I spent over an hour to isolate the error; it didn't mention which file produced the error or etc.
Strangely enough, running just tsc by itself compiles the code successfully.

class TestClass {}

module.exports = {
    default: TestClass
}

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: Declaration EmitThe issue relates to the emission of d.ts filesDuplicateAn existing issue was already created

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions