Skip to content

SignalR npm package not able to be bundled using esbuild #47674

@hrueger

Description

@hrueger

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Hi,
I'm using the npm package @microsoft/signalr with version 7.0.4. I'm using esbuild for bundeling, however, it does not correctly resolve some dependencies, like ws.

This is due those hacks:

// In order to ignore the dynamic require in webpack builds we need to do this magic
// @ts-ignore: TS doesn't know about these names
const requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;
webSocketModule = requireFunc("ws");
eventSourceModule = requireFunc("eventsource");

I don't think this is an issue of esbuild, since it believes that this is a dynamic require. Can we somehow fix this?

I confirmed that this is the issue, by patching the lib to use plain require instead of the requireFunc, then everything works correctly.

Expected Behavior

ws is resolved correctly when using the bundle option of esbuild.

Steps To Reproduce

https://github.com/hrueger/signalr-esbuild-issue

  1. yarn install
  2. yarn build
  3. See __webpack_require__ is still in dist/bundle.js instead of the ws module embedded in the bundle.

Exceptions (if any)

No response

.NET Version

n/a

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-signalrIncludes: SignalR clients and servers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions