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

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 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.


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.