Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ES6: import module from URL

Is it possible to import javascript module from external url in ES6?

I tried (using babel-node):

import mymodule from 'http://...mysite.../myscript.js'; // Error: Cannot find module 'http://...mysite.../myscript.js' 
like image 852
madox2 Avatar asked Jan 05 '16 08:01

madox2


1 Answers

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.

like image 57
Benjamin Gruenbaum Avatar answered Nov 14 '22 14:11

Benjamin Gruenbaum