3 ms·
Js has no import system. Bundlers do, and they are terrible at it though.
by sametmax 7y ago
Js has no import system. Bundlers do, and they are terrible at it though.
- ChrisSD 7y agoModern js has native modules: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- sametmax 7y agoWhich don't work in the browser, the main place we use JS.
- ChrisSD 7y agoIt does work in all modern browsers except Edge. Which I grant you might be a sticking point. However, Edge is moving to Chromium in the near future.
- sametmax 7y agoFirefox 66: import('/modules/mon-module.js') SyntaxError: dynamic module import is not implemented So no network access, and of course no FS access. Hence, doesn't work in the browser. You need a lib or a bundler.
- ChrisSD 7y agoI'm also using Firefox 66 and it works for me. Here's a live example: https://mdn.github.io/js-examples/modules/basic-modules/ https://mdn.github.io/js-examples/modules/basic-modules/ Source code and other examples are at: https://github.com/mdn/js-examples/tree/master/modules https://github.com/mdn/js-examples/tree/master/modules