When using TypeScript with module: "commonjs"
, I am facing issues with importing exported classes.
For example, let's consider an exported class called Train:
export class Train {}
Now, my intention is to instantiate this Train class in another file like so:
import { Train } from "./Train";
class Main {
var train = new Train();
console.log("All aboard the train!", train);
}
However, upon trying this, I encounter the following errors:
GET http://localhost:3000/Train 404 (Not Found)
(index):10 Error: Fetch error: 404 Not Found
Instantiating http://localhost:3000/Train
Loading http://localhost:3000/App.js
Loading App.js
at fetch.js:37
at <anonymous>
The head
section of my index.html
is structured as follows:
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script>
System.config({
"defaultExtension": "js"
});
System.import('dist/App.js').catch(function(err){ console.error(err); });
</script>
If I append .js to the import statement, the error disappears, but unfortunately, the console.log
doesn't execute either. Any ideas on what might be causing this issue?