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

前端 未结 7 2126
暗喜
暗喜 2021-02-01 02:41

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 p

7条回答
  •  攒了一身酷
    2021-02-01 03:03

    I had the same issue with a js file generated by the Typescript compiler. Same line :

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

    And same error :

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

    I was defining a Game class in this file. I solved the issue by adding this at the end of my game.ts file:

    export = Game;
    

    With this, the Typescript compiler replaced:

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

    with:

    module.exports = Game;
    

    No more error for me after this.

提交回复
热议问题