Search code examples
javascripttypescript

Uncaught ReferenceError: exports is not defined in filed generated by Typescript


I'm trying to get started with Typescript for Electron development. After wrestling with getting typing for node and jQuery, I finally got my .ts file error free.

The problem is now that when I run my app, I get this error:

index.js:2 Uncaught ReferenceError: exports is not defined

These are the first two lines in index.js:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

I don't know that that line does. Typescript added it when compiling. My app works fine if I remove it.

How do I get rid of this error?

Oh and here's my tsconfig, if that's relevant.

{
    "compilerOptions": {
        "target": "es6",
        "module": "commonjs",
        "moduleResolution": "node",
        "isolatedModules": false,
        "jsx": "react",
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "declaration": false,
        "noImplicitAny": false,
        "noImplicitUseStrict": false,
        "removeComments": true,
        "noLib": false,
        "preserveConstEnums": true,
        "suppressImplicitAnyIndexErrors": true
    },
    "exclude": [
        "node_modules",
        "typings/browser",
        "typings/browser.d.ts"
    ],
    "compileOnSave": true,
    "buildOnSave": false,
    "atom": {
        "rewriteTsconfig": false
    }
}

Solution

  • There is an issue with the new version of typescript 2.2.1, try using the older version 2.1.6, that solved the exact same issue which you have for me.

    Version 2.2.1 on compiling adds this line Object.defineProperty(exports, "__esModule", { value: true }); while the older 2.1.6 does not.