I have a .ts file in my project which makes use of imports. These imports, of course, don't work in the browsers, so I want to compile my typescript files to be supported in browsers
{
"compilerOptions": {
"noImplicitAny": true,
"lib": ["es2017", "es7", "es6", "dom"],
"module": "CommonJS",
"target": "es5"
},
"files": [
"test.ts"
]
}
Just for testing, I added the test.ts. It's contents are
import Axios from "axios";
var axios = Axios.create();
axios.get("https://www.example.com");
Now, when I run the build process, this is the result
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var axios_1 = require("axios");
var axios = axios_1.default.create();
axios.get("https://www.example.com");
And when I use this in my index.html
<script src="test.js"></script>
It simply says ReferenceError: exports is not defined
I can't imagine that it can be so hard and difficult to compile TypeScript using imports to browser-compatible JavaScript. Any help would be greatly appreciated.