How to fix the ‘TypeScript ReferenceError: exports is not defined’ with TypeScript?

Sometimes, we want to fix the ‘TypeScript ReferenceError: exports is not defined’ with TypeScript.

In this article, we’ll look at how to fix the ‘TypeScript ReferenceError: exports is not defined’ with TypeScript.

How to fix the ‘TypeScript ReferenceError: exports is not defined’ with TypeScript?

To fix the ‘TypeScript ReferenceError: exports is not defined’ with TypeScript, we can set the module option to 'es6' is tsconfig.json.

For instance, we write

{
  //...
  "compilerOptions": {
    "module": "es6",
    "target": "es5"
  }
  //...
}

to set compilerOptions.module to 'es6' to fix the ‘TypeScript ReferenceError: exports is not defined’ error thrown during compilation.

Conclusion

To fix the ‘TypeScript ReferenceError: exports is not defined’ with TypeScript, we can set the module option to 'es6' is tsconfig.json.