-
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
Import map not working with Worker #6675
Comments
@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 |
@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
|
@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 |
From https://github.com/WICG/import-maps#installation
Related discussion: WICG/import-maps#2 Let's wait until proper solution is decided in the spec repo before implementing it in Deno. |
Is there currently any way to test a web server that is using an import map until this is implemented in Deno? |
Until there is an standardized way for import maps in Workers, ca we please have it under the |
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 |
Is there any possibility to get this implemented at least behind the unstable flag for now? |
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. |
Currently, Workers have the Maybe a solution, that I believe won't conflict with what WHATWG decide in the future is include a way to set the deno config file (deno.json), so the import map would be taken from that file. This not only allows to configure the import maps but also other things like TypeScript options, etc. A proposal: const worker = new Worker(new URL("./worker.js", import.meta.url).href, {
type: "module",
deno: {
permissions: "none",
config: "inherit" // Or the path to a different file
},
}); |
it might be possible to write a swc plugin and run the files through swc before running them in deno. the plugin would basically visit all the named imports/exports and replace the specifier as per the import_map. |
ChatGPT says we can do this: Qs:
|
It seems like this is working fine for me? It seems to pick up the import map from my deno.json. I'm using the |
Import maps in workers function properly here, too.
|
Marking as resolved. |
Steps to reproduce
import_map.json
color.ts
main.ts
Expected output
Actual output
Environment
The text was updated successfully, but these errors were encountered: