A dilemma I encountered:
<script src="./Snake.js" type="text/javascript"></script>
was added to my HTML file.
I have a file named Snake.ts
which I am compiling to JS using the below configuration:
{target: "es6", module: "commonjs"}
However, Typescript is converting my import statements to require function (compatible only with NodeJS). This leads to a browser error:
Uncaught ReferenceError: require is not defined.
Surprisingly, I do not have any require statements in my code. Instead, Typescript automatically swaps import statements with the require function instead of
import Game from './Game';
I have experimented with various solutions, including changing to and, umd, es2020. Oddly, it was functioning correctly just yesterday.
Any suggestions on how to compile Typescript code to work on both browser JavaScript and NodeJS?