Categories
TypeScript Answers

How to fix Uncaught ReferenceError: exports is not defined in filed generated by TypeScript?

Spread the love

To fix Uncaught ReferenceError: exports is not defined in filed generated by TypeScript, we fix the project config.

In tsconfig.json, we write

{
  "compilerOptions": {
    "target": "ESNext",
    "module": "CommonJS",
    "lib": ["DOM", "ES5"],
    "esModuleInterop": true
  }
}

to set esModuleInterop to true to compile ES6 modules.

And we remove "type": "module" from package.json to fix the error.

By John Au-Yeung

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

Leave a Reply

Your email address will not be published.