6 ms·
If you decide to work with ESM there's only one issue I have with them in practice: There's no way to remap a "global package identifier" to the entry point (e.
by cookiengineer 6y ago
If you decide to work with ESM there's only one issue I have with them in practice: There's no way to remap a "global package identifier" to the entry point (e.g. remap import from "package" to "../path/to/mymodules/package/index.mjs") on the Browser-side.
Node.js has the workaround with the "exports{}" map in the package.json file, but there is no equivalent on the Browser-side, so you constantly have to work with dozens of "../../to/index.mjs" files as wrappers that do nothing more than a lot of "export * from ./some/other/file.mjs" inside them, which is a bit annoying.
As a side note (most people aren't aware of it): All Browsers have support for ESM modules, including Safari; and even WebKit2GTK. [1]
[1] https://caniuse.com/es6-module https://caniuse.com/es6-module
- Zardoz84 6y agoIE11 not
- deleted 6y ago[deleted]
- imbnwa 6y agoDunno why this is downvoted, IE11 isn't going anywhere in some rather crucial places, like all healthcare
- deleted 6y ago[deleted]
- timdaub 6y ago> There's no way to remap a "global package identifier" to the entry point (e.g. remap import from "package" to "../path/to/mymodules/package/index.mjs") on the Browser-side. I think what you're looking for is `require.resolve` [1]. ```mjs import { createRequire } from "module"; const require = createRequire(import.meta.url); const path = require.resolve("package"); console.log(path); >> ../path/to/mymodules/package/index.mjs ``` 1: https://nodejs.org/api/esm.html#esm_no_require_resolve https://nodejs.org/api/esm.html#esm_no_require_resolve
- cookiengineer 6y agoI was talking about Browser-side, the cleaner node.js solution is to use the "exports{}" map in the package.json [1] that I mentioned before. Personally, I wouldn't recommend to override the require.resolve or import.meta.resolve algorithm, as this is heavily experimental. [1] https://nodejs.org/api/packages.html#packages_exports https://nodejs.org/api/packages.html#packages_exports
- reaktivo 6y agoI'm hoping for the import-map[1] spec to supported soon. 1 https://blog.logrocket.com/es-modules-in-browsers-with-import-maps/ https://blog.logrocket.com/es-modules-in-browsers-with-impor...