Is anyone shipping multiple ESM entry points in the same JavaScript package? e.g. if I want to ship a "react-router/hooks" bundle in the same package as the router itself, how can I enable someone to `import` from the ESM version (instead of translating CJS)?
-
Show this thread
-
Right now we use the `module` field in package.json to give bundlers a hint about where to find the ESM version of our main bundle. But can we do that for "sub"-bundles? Or should we just publish a new package?pic.twitter.com/LKlFwKT3R0
4 replies 0 retweets 3 likesShow this thread -
/cc a few people who I know have done a lot of thinking about ESM and modules and npm packages
@MylesBorins@Rich_Harris@_developit5 replies 0 retweets 5 likesShow this thread -
So not 100% if this is what you asking about... But we are talking about a proposal for "export maps" that would allow you to explicitly reference deep modules on the pkg.json, the hope would be that other tools would be able to use this to generate import map
2 replies 0 retweets 3 likes -
Replying to @MylesBorins @mjackson and
sMyle Retweeted sMyle
I'm p convinced at this point that dual-mode modules, Modules that have multiple entry points for the same bare specifier, is a massive anti patternhttps://twitter.com/MylesBorins/status/1128845933599502336?s=19 …
sMyle added,
sMyleVerified account @MylesBorinsReplying to @MylesBorins @evanplaicePrior to 12.x dual mode modules worked because of automatic file extension resolution set `main: index` and then have index.mjs and index.js and you are off the races. You can have a single specifier that just works for both loaders4 replies 0 retweets 3 likes -
it would be more this: import 'preact/hooks'; where node_modules/preact/hooks/package.json is: { "module": "dist/preact.mjs", "main": "dist/preact.js" }
1 reply 0 retweets 0 likes -
Replying to @_developit @MylesBorins and
the usage only affects importing a directory.
1 reply 0 retweets 0 likes -
This then seems to fall squarely in the anti pattern I was mentioning A specifier should mean one thing and one thing only. The es loader shouldn't get a different resource then the cjs loader.
2 replies 0 retweets 4 likes
Import maps set a different precedent, though. I think it’d be beneficial to follow that example in the Node.js/npm world.
-
-
Replying to @mathias @_developit and
I'm going to digest this
Would enjoy talking about this point more.1 reply 0 retweets 3 likes -
Replying to @MylesBorins @mathias and
Do import maps really set a different precedent? The may remap a specifier, but it still means the same thing for the whole scope. The hazard
@MylesBorins points out is that one import could resolve to JS modules and one to CJS not based on the mapping.1 reply 0 retweets 2 likes - 1 more reply
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
JavaScript, HTML, CSS, HTTP, performance, security, Bash, Unicode, i18n, macOS.