Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript is adding Object.defineProperty(exports, "__esModule", { value: true }); throwing an error

I have recently updated typescript at the new version 2.2.1 after this I began to receive this error on the browser:

Uncaught (in promise) Error: "exports is not defined"

I noticed that typescript is adding this line after "use strict" at the began of the .js transpile file when the there is an import statement at the .ts file.

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

So I re installed the previous version 2.1.6 and that line disappeared and everything works fine again.

Is this an expected behavior of this new version? How could I go throw this?

By the way I'm using SystemJS with JSPM

like image 241
Diego Avatar asked Mar 16 '17 14:03

Diego


People also ask

How do you solve uncaught ReferenceError exports is not defined?

To solve the "Uncaught ReferenceError: exports is not defined", add a script tag that defines an exports variable, e.g. <script>var exports = {};</script> above your JS script tag if in the browser, or remove the type attribute if set to module in your package.

What are exports in TypeScript?

TypeScript supports export = to model the traditional CommonJS and AMD workflow. The export = syntax specifies a single object that is exported from the module. This can be a class, interface, namespace, function, or enum.


1 Answers

I find the same issue. Uncaught ReferenceError: exports is not defined and require

This solution is work for me. I change the setting of "tsconfig.json"

{
  "compilerOptions": {
    "target": "es5",
    "module": "umd"
  }
}
like image 196
Bibby Chung Avatar answered Sep 23 '22 14:09

Bibby Chung