D
Deno

help

using imports map to map no-suffix imports to suffix imports

Aandy11/17/2023
I was hoping i might be able to use an import map in my deno.json like this:
"imports": {
"./supabase":"./supabase.ts"
}
"imports": {
"./supabase":"./supabase.ts"
}
But that doesn't seem to work. From what I'm finding online there is no solution to this currently? Just seemed like making the mapping explicit in this way would be a nice workaround for the side-effect that the intentional decision to require suffixes has had on compatibility with existing libraries. FWIW, I like the design choice, but why not let us use the mapping to bridge the two worlds? Unless it is possible to us the imports map in this way and I'm just getting the syntax wrong.
DAHDeno AI Helper11/18/2023
According to the documentation, import maps in Deno are used to map "bare" specifiers to URLs. This means that they are primarily used to map module names to their corresponding URLs, not to add file extensions to local imports. In your case, you're trying to use an import map to add a .ts extension to a local import, which is not supported. The import map feature doesn't support this kind of mapping. The documentation states that import maps are not composable, meaning you can only provide a single import map to deno run or deno test. This is because import maps are designed to remap specifiers to completely different ones, not to add extensions to existing ones. The documentation also mentions that import maps are only applied for Deno applications, not in the various libraries that your application code may import. This means that if you're developing a library, you should use the deps.ts pattern instead. So, unfortunately, you can't use import maps to add file extensions to local imports. The requirement for explicit file extensions in Deno is a design decision that aims to avoid the ambiguity and complexity associated with module resolution in other JavaScript environments. 🦕

Looking for more? Join the community!