cloudflare-worker-router icon indicating copy to clipboard operation
cloudflare-worker-router copied to clipboard

Consider dropping the `default` export in favor of named exports

Open AlCalzone opened this issue 3 years ago • 0 comments
trafficstars

Currently when bundling this into a module worker using esbuild, the module including the default export gets wrapped again in {default: /* original module */}. Details why are explained here: https://esbuild.github.io/content-types/#default-interop under "The Node interpretation"

As a result, one has to access the Router class using this awkward way

import Router_default from "@tsndr/cloudflare-worker-router";
const Router = Router_default.default;

which totally breaks down when needing types too.

To resolve this, I had to create a local copy, remove default from the export and import this way:

import { Router } from "./cloudflare-worker-router";

AlCalzone avatar Aug 31 '22 15:08 AlCalzone