tsndr / cloudflare-worker-router

A super lightweight router (1.0K) with middleware support and ZERO dependencies for Cloudflare Workers.
MIT License
227 stars 30 forks source link

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

Closed AlCalzone closed 2 years ago

AlCalzone commented 2 years ago

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";
tsndr commented 2 years ago

Thank you for bringing this up, here you go: v2.2.0