我正在像這樣創建連接,它以前作業正常,但現在顯示錯誤。
這是我得到的錯誤
hub failed ReferenceError: document is not defined
at HubConnection._startWithStateTransitions$ (HubConnection.js:110)
at tryCatch (runtime.js:63)
at Generator.invoke [as _invoke] (runtime.js:294)
at Generator.next (runtime.js:119)
at tryCatch (runtime.js:63)
這是我的代碼。
const createConnection = () => {
_hubConnection = new HubConnectionBuilder().withUrl(SOCKET_HUB_URL, {
skipNegotiation: true,
transport: HttpTransportType.WebSockets,
})
.withAutomaticReconnect([0, 0, 0, 0, 0])
.build();
setTimeout(() => {
_hubConnection.start()
.then((data) => {
console.log('hub started', data);
refreshMessages();
})
.catch(err => {
console.log('hub failed', err);
});
}, 5000);
}
提前致謝
uj5u.com熱心網友回復:
您可以通過添加以下內容來解決此問題:
if (!globalThis.document) {
(globalThis.document as any) = undefined;
}
到您的應用程式。有關更多背景關系,請參閱https://github.com/dotnet/aspnetcore/issues/38286#issuecomment-970580861。
uj5u.com熱心網友回復:
我可以通過將這兩行放在我的函式的開頭來解決這個問題
if (!globalThis.document) {
(globalThis.document as any) = undefined;
}
像這樣
const createConnection = () => {
if (!globalThis.document) {
(globalThis.document) = undefined;
}
_hubConnection = new HubConnectionBuilder().withUrl(SOCKET_HUB_URL, {
skipNegotiation: true,
transport: HttpTransportType.WebSockets,
})
.withAutomaticReconnect([0, 0, 0, 0, 0])
.build();
_hubConnection.start()
.then((data) => {
console.log('hub started', data);
refreshMessages();
})
.catch(err => {
console.log('hub failed', err);
});
}
它現在是一種解決方法,希望通過@microsoft/signlr 的更新版本進行修復
有關更多詳細資訊,請查看以下鏈接 https://github.com/dotnet/aspnetcore/issues/38286
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/367848.html
上一篇:如何在ReactNative的底部標簽欄后面制作模態
下一篇:谷歌腳本洗掉關鍵字后的所有文本
