-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to specify default extension for extension-less imports #194
Comments
If you import |
@matthewp The extension would be added only if:
|
Does the web platform have an algorithm for determining an extension? If not you'd need to come up with one. The presence of a dot doesn't work because some times filenames contain a dot that is not for the extension, for example |
@matthewp the extension there is only |
@ljharb Yes, but if the import is |
Files do not need to have extensions. In this world, how would I import the file at Also see #89. |
I agree that by default there should be no extension logic applied; but it seems like it should be possible for me to say "everything in this import map scope should automatically have a suffix applied to the RHS, if it doesn't endWith() it" - we don't even have to call it an "extension". |
Also need to think about what happens when there are multiple types of modules. For example if we have wasm modules, the |
I'd use a different import map scope for those. |
Dupe of #89 :) |
#89 is closed with comment that:
This issue proposes way to be at the same time explicit and allow extension-less imports. Could you explain why you don't want to allow extension-less imports even if they can be explicitly configured with import map? |
The readme is fairly explicit about this: https://github.com/WICG/import-maps#extension-less-imports. It's not encouraged, but if you really want to do it, you can generate a giant import map. |
I've already commented about the quote you link here: nodejs/modules#444 This looks like by-design flaw that could be solved by something as simple as proposed option. This issue provides a way to explicitly and simply configure extension-less imports in import-map, can solve nodejs/modules#444 and also can solve issue you are linking to. Why not allow it? |
Referencing: nodejs/modules#444 and #7
Node could theoretically implement extension-less imports for ES6 modules but the main argument against is that it's not possible to statically generate import map for extension-less imports like
import first from 'lodash/first'
(without listing each possible file in import map).This use case could be rather easily solved by allowing to specify default extension to add if imported package is not found as exact match in import-map and no extension is provided.
For example:
would make
import first from 'lodash/first'
to import/node_modules/lodash-es/first.js
instead of/node_modules/lodash-es/first
.Arguably this could be also made a default behavior. No pattern matching like proposed in #7 is really necessary for 99% of cases.
The text was updated successfully, but these errors were encountered: