Open hrueger opened 1 year ago
Looks like an esbuild issue https://github.com/evanw/esbuild/issues/1921
Are you sure? I don't think so, to be honest. This is not about esm / cjs, but instead the workaround which is implemented for webpack here, breaks other bundlers (at least esbuild). To those, the call looks like a dynamic require, although it is actually not dynamic. Do you know, what I mean?
We are facing the same issue with 5.0.17. The workaround was to replace the __non_webpack_require__ with require using webpack plugin.
{
test: /@microsoft.signalr.dist.cjs.(HttpConnection|FetchHttpClient)\.js/,
loader: 'string-replace-loader',
options: {
search: /__non_webpack_require__/g,
replace: 'require',
strict: true
}
}
The question I want to ask is why is __non_webpackrequire_\ is being used because after searching online, it seems like it is not meant to be used in production code and no other package uses it.
Thanks!
Unfortunately this issue will need to be reopened. The fix we made broke other important scenarios so we'll need to find a different way to fix this. Starting with 8.0.7 this esbuild issue will start happening again.
@BrennanConroy did it break multiple scenarios or just the esbuild thing?
For bundling with rollup
(for Electron Main), I also have to use an ugly workaround involving the replace
plugin. Needless to say that this is very unsatisfactory.
replace({
preventAssignment: true,
include: [
'./node_modules/@microsoft/signalr/dist/**/*'
],
values: {
// @microsoft/signalr 8.0.7
'/*#__PURE__*/': '',
'new (requireFunc("tough-cookie")).CookieJar()': 'undefined',
'this._fetchType = requireFunc("fetch-cookie")(this._fetchType, this._jar);': JSON.stringify(''),
'requireFunc("ws")': 'undefined',
'requireFunc("eventsource")': 'undefined'
},
delimiters: ['', '']
}),
In addition, the private WebSocket
and EventSource
properties have to be set in IHttpConnectionOptions
manually. And this workaround wouldn't work with cookies.
Is there an existing issue for this?
Describe the bug
Hi, I'm using the npm package
@microsoft/signalr
with version7.0.4
. I'm usingesbuild
for bundeling, however, it does not correctly resolve some dependencies, likews
.This is due those hacks:
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 therequireFunc
, then everything works correctly.Expected Behavior
ws
is resolved correctly when using thebundle
option ofesbuild
.Steps To Reproduce
https://github.com/hrueger/signalr-esbuild-issue
yarn install
yarn build
__webpack_require__
is still indist/bundle.js
instead of thews
module embedded in the bundle.Exceptions (if any)
No response
.NET Version
n/a
Anything else?
No response