Closed andreatosato closed 6 years ago
Can you provide your webpack configuration? When using SignalR as a node module (via something like WebPack) it expects to be in a Node environment (where things like global
are defined). WebPack is supposed to automatically shim those things though.
this is my project: https://github.com/andreatosato/RealTime/tree/master/ChatPWA/chat-app Project is for conference sessions. I tried to add in polyfills.ts:
(window as any).global = window;
The introduction of the line of code indicates a new error with messagepack.
This is my experiments: 1 experiment
(window as any).global = window;
2 experiment
(window as any).process = {
env: { DEBUG: undefined },
};
Could you give step-by-step instructions on how to run the app and hit the issue?
With last commit, I migrate from Json to MessagePack protocol.
I insert polyfills rules with (window as any).global = window;
Step to reproduce error:
Yeah, I figured out those steps, but how do you actually hit the issue? It ran fine, but there is no SignalR code running in the browser.
excuse me for the misunderstanding. I encounter the problem at runtime when running the following line of code:
this.connection = new HubConnectionBuilder()
.withUrl(environment.baseHubs + '/chat', {
accessTokenFactory: () => token,
logger: LogLevel.Trace
})
.withHubProtocol(new MessagePackHubProtocol())
.build();
The strange thing is that code breaks before running start() method. It looks like a Typescript/Javascript problem in the package: @aspnet/signalr-protocol-msgpack
Got it running by adding more polyfill bits. Just had to follow stackoverflow for a couple more things
(window as any).global = window;
(window as any).process = {
env: { DEBUG: undefined },
version: "1",
};
global.Buffer = global.Buffer || require('buffer').Buffer;
https://stackoverflow.com/questions/50371593/angular-6-uncaught-referenceerror-buffer-is-not-defined
Wow, great! Thanks a lot! @BrennanConroy
Complete resolution: index.html
<head>
<script>
var global = global || window;
var Buffer = Buffer || [];
var process = process || {
env: { DEBUG: undefined },
version: []
};
</script>
</head>
polyfills.ts
(window as any).global = window;
(window as any).process = {
env: { DEBUG: undefined },
version: '1',
};
Angular error:
Client Side
Server Side
When I change protocol to Json all work fine: Client Side
Server Side