deno: Import map not working with Worker
Steps to reproduce
- Create the following files under the same directory:
import_map.json
{
"imports": {
"fmt/": "https://deno.land/std@0.55.0/fmt/"
}
}
color.ts
import { red } from "fmt/colors.ts";
console.log(red("hello world"));
main.ts
new Worker(new URL('./color.ts', import.meta.url).href, {type: 'module'})
- Run this command:
deno run --allow-read --importmap=import_map.json --unstable main.ts
Expected output
hello world
Actual output
error: Uncaught Error: relative import path "fmt/colors.ts" not prefixed with / or ./ or ../ Imported from "file:///color.ts"
Environment
deno 1.1.3
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 5
- Comments: 20 (12 by maintainers)
@wongjiahau that would be something like:
I guess the spec will take a long time to decide a final solution, and import maps is something very popular and used right now in Deno, so I believe Deno should provide a way to handle this. The
importMapskey underdenoproposed in https://github.com/denoland/deno/issues/6675#issuecomment-657018192 seems the obvious choice.According to import maps spec they are not affecting workers. So rather than a bug this would be a feature and would be Deno specific. It could be added to non-standard
denooption inWorkerconstructor.No, because we want to continue to align to the web standard. If the web standard is strongly considering establishing a proposal, then we might consider it. Best thing to do is continue to champion something with WHATWG.
Until there is an standardized way for import maps in Workers, ca we please have it under the
denooptions? ATM this issue throws a wrench into applications designed to work with import maps…@wongjiahau that’s correct
@wongjiahau not at the moment, there is a PR for it (#5849), but I haven’t reviewed it yet