Im getting this error message (Uncaught ReferenceError: exports is not defined) when trying to import other ts files in the main app.ts
app.ts
import { LanguagesConfigs } from './LanguagesConfigs';
let languagesConfigs = new LanguagesConfigs();
LanguagesConfigs.ts
export class LanguagesConfigs {
code
}
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"sourceMap": true
}
}
I compile it in visual studio code. It generates the .js and .js.map files
Note: I'm not using frames like angular, just plain typescript. Note2: CommonJS is installed in the project (Typescript ReferenceError: exports is not defined)
When you use export in your code while in your tsconfig.json you have "module": "commonjs" the result code assume commonjs module style.
For example:
export class Foo{}
Will result is:
.
.
.
exports.Foo = Foo;
So when you try to run the result js code you will get this error if the environment doesn't support commonjs.
For example, browsers do not support commonjs but nodejs does.
You can add commonjs support to the browser by using webpack or just add browserify
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With