Categories
TypeScript Answers

How to fix the ‘Uncaught ReferenceError: exports is not defined’ error in files generated with TypeScript?

Spread the love

Sometimes, we want to fix the ‘Uncaught ReferenceError: exports is not defined’ error in files generated with TypeScript.

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

How to fix the ‘Uncaught ReferenceError: exports is not defined’ error in files generated with TypeScript?

To fix the ‘Uncaught ReferenceError: exports is not defined’ error in files generated with TypeScript, we should remove the "type": "module" option from tsconfig.json.

For instance, if we have

{
  //...
  "type": "module"
  //...
}

in tsconfig.json then we should remove it so that the TypeScript compiler will transpile the code into something that doesn’t have export and import in the generated files.

Conclusiun

To fix the ‘Uncaught ReferenceError: exports is not defined’ error in files generated with TypeScript, we should remove the "type": "module" option from tsconfig.json.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.