import_map.json
{
"imports": {
"fmt/": "https://deno.land/[email protected]/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'})
deno run --allow-read --importmap=import_map.json --unstable main.ts
hello world
error: Uncaught Error: relative import path "fmt/colors.ts" not prefixed with / or ./ or ../ Imported from "file:///color.ts"
deno 1.1.3
@ry If I want to fix this which files should I look at?
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 deno option in Worker constructor.
@bartlomieju I see, so is it something like ‘importMap: URL’ option for Worker?
Having import map loading different context of modules could introduce interesting use cases for stuff like A/B testing
@wongjiahau that would be something like:
declare class Worker extends EventTarget {
constructor(
specifier: string,
options?: {
type?: "classic" | "module";
name?: string;
deno?: {
importMap?: string
};
}
);
}
@bartlomieju Can the import map represents a remote file? for example
https://deno.land/x/import_map.json
@wongjiahau not at the moment, there is a PR for it (#5849), but I haven't reviewed it yet
@bartlomieju Ok, so importMap can only be either relative or absolute file path right?
@wongjiahau that's correct
@bartlomieju Thanks I will create a PR based on the direction you provided
Most helpful comment
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.