Skip to content
Latchkey

esbuild "Could not resolve './worker'" (web worker) in CI

esbuild could not find the web worker module referenced by new Worker(new URL("./worker", import.meta.url)) because the worker entry was not provided to the build or the URL form is unsupported.

What this error means

The build fails with "Could not resolve './worker'" pointing at a Worker construction. The file exists on disk, but the bundler never treats it as an entry point.

node
> ERROR: Could not resolve "./worker"

    src/main.ts:3:24:
      3 | new Worker(new URL("./worker.ts", import.meta.url));
        |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Common causes

The worker is not an entry point

esbuild does not auto-discover workers from new Worker(new URL(...)). The worker file must be built explicitly.

Wrong extension or path in the URL

The URL references ./worker without an extension esbuild can resolve, or a path that does not exist after the build layout changes.

How to fix it

Add the worker as its own entry point

Build the worker file separately and reference the emitted asset, or use a plugin that understands the worker URL pattern.

build script
esbuild.build({
  entryPoints: ['src/main.ts', 'src/worker.ts'],
  bundle: true,
  format: 'esm',
  outdir: 'dist',
});

Use a tool with native worker support

Vite resolves new Worker(new URL(...)) out of the box; if you need that ergonomics, build the worker through Vite or an esbuild worker plugin.

  1. Confirm the worker file has a resolvable extension in the URL.
  2. Either add it as an entry point or adopt a plugin that emits worker chunks.
  3. Verify the emitted path matches the runtime URL.

How to prevent it

  • Treat worker files as explicit build entry points.
  • Reference workers with a resolvable extension in the URL.
  • Verify the built worker asset path matches the runtime reference.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →