Switching to all major browsers will soon be ES6 modules.
They differ from many server-side approaches in that they need to specify the exact file to import - they cannot use file detection.
This makes sense - in applications or Node bundles such as WebPack, they really only need a module name, and then they can spend a little extra time finding a specific file containing the code. On the Internet, where there can be many empty trips (the 'library' in library/index.js , or library/library.js , or library.js ? library.js require() doesn’t care, but on the Internet we have to).
TypeScript has support for ES6 modules (install "module": "es6" in tsconfig.json ), but it seems to use a file discovery approach ...
Suppose I have library.ts :
export function myFunction(...) { ... }
Then in app.ts :
import {myFunction} from './library'; var x = myFunction(...);
However, this does not change when transpiles - the TS output is still named 'library' for detecting files that do not work. This causes an error because the 'library' not found:
<script type="module" src="app.js"></script>
In order for ES6 modules to work, TS output must reference a specific file:
import {myFunction} from './library.js'; var x = myFunction(...);
How to make TS output valid ES6 import module instructions?
Note. I do not ask how to make the connector connect to the TS output in a single file. I specifically want to download these files individually using <script type="module">