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
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.
I was having the same issue, I just modified the systemjs.config.js file as mentioned below
'npm:': '/node_modules/' -- // Its value was just 'node_modules/' and I added '/' in the beginning
'app': '/src/app' -- // Its value was just 'app' and as my app folder path was different so is changed it accordingly
loader: '/src/systemjs-angular-loader.js' -- // Its value was just 'systemjs-angular-loader.js' and as its location was different in my project so pointed it to the correct path
I was also facing the same issue and tried by chagning with different versions of typescript but did not work.
Finally I got it - There was a "type": "module"
and when I removed it - it worked
I've fixed mine with the following:
tsconfig.json
{
"compilerOptions": {
"target": "ESNext",
"module": "CommonJS",
"lib": [
"DOM",
"ES5"
],
"esModuleInterop": true
}
}
Adding the esModuleInterop
Removing the "type": "module" from the package.json
I solved it with a hack in the embedding HTML:
<script> var exports = {}; </script>
<script src="index.js"></script>
Basically giving it what it wants, a global exports variable.
With that my TypeScript (2.3.2) generated file (es6) loads.
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.