-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
npm: Import map is not supported for "require()" #15948
Comments
@guybedford I would appreciate your thoughts on this topic. |
Potentially related, when loading plugins from a CLI, it would be nice to have more fine-grained control over how imports are mapped when using both ESM and CJS #8655 (comment) |
@bartlomieju not sure I have much to add on this, but can share my thoughts certainly. In Node.js loader hooks are not currently supported for CommonJS require, so that a userland import map implementation will likely only apply to ESM, although could hook into the require system using the standard monkey patching as well. The new loader work does point in the direction of loaders being able to have more general hooks so that this might be supported in future. So it may well be possible, but yet to be seen if Node.js implementing import maps would also want to extend that to require. Typically Node.js does aim to support for CommonJS for new resolution features (like we did with "imports" and "exports"). In terms of CommonJS and ESM having different resolutions ( So overall it seems useful to me, but it could be helpful to ensure it matches what Node.js does itself. On a related note, has there been any discussion of supporting scoped maps for |
@guybedford thank you for the time you took to respond. Since opening this issue we managed to overcome problems at hand and I no longer believe we should be adding import map support for
That makes total sense and is inline with browser behavior so I think we should keep it that way.
Thanks for pointing this out, definitely something to keep an eye on, but again before this edge case is hit I think we should stay put.
Not yet, but I think this would be very useful for quickly patching dependencies locally. @dsherret any thoughts on this? |
We have support for import map in case of ESM imports of npm: specifiers, but it's not supported if a module is
require
d.This might be a bit exotic, but I believe there are certain valid use cases for it.
Eg. I'm trying to run a Vite project, I did set up following import map:
This works nicely, as long as there's a
package.json
file in the same directory like so:However as soon as I remove that
package.json
file, I'm no longer able to rundeno run -A --unstable npm:vite
, because I get following error:If
require()
took into account import map file, just like ESM imports do, then we could removepackage.json
from the project altogether and instead replace it withdeno.json
+import_map.json
.The text was updated successfully, but these errors were encountered: