TranscryptOrg / Transcrypt

Python 3.9 to JavaScript compiler - Lean, fast, open!
https://www.transcrypt.org
Apache License 2.0
2.84k stars 213 forks source link

What is the best way to import a library when its type='module'? #875

Closed chopin closed 1 month ago

chopin commented 2 months ago

Hi,

I am trying to import a 3rd party library (Trystero), This library should be imported by tags. It looks better than using pragma ()

The relevant section of document doesn't mention how to import in case of module type. I hope that this section is updated to include this case 6.1.1. Three ways of integration with JavaScript libraries:

JennaSys commented 1 month ago

Did using the script tag as above work in your case?

I'm not sure if it impacts the issue, but I also just noticed the braces weren't doubled in the string of your pragma:

__pragma__('js', '{}', '''
import {{joinRoom}} from './../trystero-torrent_min.js';
''')
chopin commented 1 month ago

Yes, using the script tag above worked nicely to me. Also, the compile error from the second trial disappeared too.

Thanks for pointing out the the braces not doubled. They might have been the cause of the compile error. Anyway the problem solved now. Thanks again.

JennaSys commented 1 month ago

The relevant section of document doesn't mention how to import in case of module type. I hope that this section is updated to include this case 6.1.1. Three ways of integration with JavaScript libraries

As suggested, this section of the documentation has been updated.