Categories
TypeScript Answers

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

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *