I need to use a Javascript library (https://unpkg.com/[email protected]/dist/textmesh-standalone.esm.js?module) which is only delivered as a module. When I try to import the class TextMesh in my non-module script build.js, the console gives me that error-message:
Cannot use import statement outside a module
So I needed to make build.js a module. But I have many non-module scripts, which are dependant from that build.js, which now also need to become modules. And I have many other non-module scripts, which are dependant from them, which then also need to become modules. And so on, ...
Where is my misunderstanding of the concept of JavaScript modules, because it can't be the intent of modules, that all scripts which are (in)directly dependant from that 'first' module, must become a module, too?!
You can use dynamic import() even in non-module scripts:
(async()=>{
const { TextMesh } = await import("https://unpkg.com/[email protected]/dist/textmesh-standalone.esm.js?module");
console.log( TextMesh );
})();
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