Skip to content

Import map not being applied to user workers #621

@0x5457

Description

@0x5457

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

Import maps are not being properly resolved when creating user workers, despite being correctly specified via the importMapPath context option. This results in module resolution failures for bare specifiers that should be mapped according to the import map configuration.

This functionality worked in previous versions but has regressed in the current version.

Error Message

worker boot error: failed to bootstrap runtime: failed to create the graph: Relative import path "test" not prefixed with / or ./ or ../ and not in import map from "file:///path/to/code/edge-runtime/examples/hello-world/index.ts"
  hint: If you want to use a built-in Node module, add a "node:" prefix (ex. "node:test").
    at file:///path/to/code/edge-runtime/examples/hello-world/index.ts:1:18

To Reproduce

Setup

Approach 1: File-based Import Map

  1. Import Map File (examples/main/import_map.json):
{
  "imports": {
    "oak": "https://deno.land/x/[email protected]/mod.ts",
    "shared_cors": "./_shared/cors.ts",
    "test": "./user/test.ts"
  }
}
  1. User Worker Code (examples/hello-world/index.ts):
import test from "test";

Deno.serve(async (req: Request) => {
  return new Response(
    test(),
    {
      headers: {
        "Content-Type": "application/json",
        "Connection": "keep-alive",
      },
    },
  );
});
  1. Module Being Imported (examples/main/user/test.ts):
export default function test() {
  return "test";
}
  1. Worker Creation Code (examples/main/index.ts):
return await EdgeRuntime.userWorkers.create({
  servicePath,
  memoryLimitMb,
  workerTimeoutMs,
  noModuleCache,
  envVars,
  forceCreate,
  cpuTimeSoftLimitMs,
  cpuTimeHardLimitMs,
  staticPatterns,
  context: {
    useReadSyncFileAPI: true,
    otel: otelAttributes,
    importMapPath: "./import_map.json",  // ← Import map specified here
  },
  otelConfig: {
    tracing_enabled: true,
    propagators: ["TraceContext", "Baggage"],
  },
});

Approach 2: Inline Data URL Import Map

const inlineImportMap = {
  imports: {
    "test": "./user/test.ts"
  },
};
const importMapPath = `data:${encodeURIComponent(JSON.stringify(inlineImportMap))}?${
  encodeURIComponent(import.meta.dirname!)
}`;

return await EdgeRuntime.userWorkers.create({
  servicePath,
  memoryLimitMb,
  workerTimeoutMs,
  noModuleCache,
  envVars,
  forceCreate,
  cpuTimeSoftLimitMs,
  cpuTimeHardLimitMs,
  staticPatterns,
  context: {
    useReadSyncFileAPI: true,
    otel: otelAttributes,
    importMapPath: importMapPath,  // ← Inline import map via data URL
  },
  otelConfig: {
    tracing_enabled: true,
    propagators: ["TraceContext", "Baggage"],
  },
});

Both approaches (file-based and inline data URL) result in the same module resolution error.

Additional context

Note: I'm willing to submit a PR to fix this issue if needed.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions