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.