Es6: Import Module from Url

ES6: import module from URL

2018 Update: The module loader spec is now a part of the ES Spec - what you are describing is allowed and possible with <script type="module"> in browsers and with a custom --loader with Node.js as well as with Deno if you're into that.


The module loader spec and the import/export syntax are separate. So this is a property of the module loader (not a part of the ES spec). If you use a module loader that supports plugins like SystemJS.

Import ES6 module from http url in Typescript

Thanks to @acrazing's comment, I managed to resolve this problem. Here's how:

In a new ts file:

declare module 'https://*'

This mutes the error that Typescript compiler attempts to read type declaration.

If you want to access type declaration as a node dependency, paste this in a new ts file:

declare module 'https://cdnjs.cloudflare.com/ajax/libs/redom/3.26.0/redom.es.js' {
export * from 'redom'
}

and add redom dependency in package.json

  "dependencies": {
"redom": "3.26.0",
...
},

Then, type declaration is read from local ./node_modules directory, VSCode recognizes the types as well.

es6 modules: import specific-functions as aName

There are no alternatives to the two ways you already mentioned. Readability is subjective, but both exporterGet() and exporter.get() are good choices that are common. If you explicitly want to list all the used function in the import statement itself, you will have to give them individual aliases. Tree shaking tools will be able to handle both formats.



Related Topics



Leave a reply



Submit