Skip to content

Make it easier to bundle @trpc/server #1375

Closed

Description

@esamattis

Currently it requires two workarounds

  1. The url module must be installed from npm since it is a Node.js build-in and cannot be bundled otherwise
  2. Imports to http module must be ignored manually

With these workarounds I was able to bundle it with esbuild using this script

const ignorePlugin = require("esbuild-plugin-ignore");
require("esbuild").build({
    entryPoints: ["src/worker.ts"],
    bundle: true,
    outfile: "dist/worker.js",
    target: "chrome96",
    plugins: [
        ignorePlugin([
            {
                resourceRegExp: /http$/,
                contextRegExp: /.*/,
            },
        ]),
    ],
});

Why?

Bundling allows to run it non-node.js environments such as Cloudflare Workers, browsers, Remix in without node.js and possibly in Deno too.

Here's a proof of concept running it in a Cloudflare Workers https://github.com/esamattis/trpc-cloudflare-worker

What could be done?

The url module installation is OKish workaround but it would better to just get rid of it and use URLSearchParams instead which is available as a global in all these environments including Node.js.

The import { router } from "@trpc/server" should not end importing the http module. Only the adapter file using it should import it.

Activity

  1. KATT commented on Jan 10, 2022

    @KATT
    Member
  2. pinned this issue on Jan 11, 2022
  3. unpinned this issue on Jan 11, 2022
  4. KATT commented on Mar 6, 2022

    @KATT
    Member

    Superseded by #1597. If you wanna work on it, I'll pay you. :)

  5. github-actions commented on Oct 4, 2022

    @github-actions
    Contributor

    This issue has been locked because it had no new activity for 14 days. If you are running into a similar issue, please create a new issue. Thank you.

  6. locked as resolved and limited conversation to collaborators on Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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