Hi, maybe one of you can help me.
I compile my Typescript code with ESBuild.
I get the following error when I try to run my code:
TypeError: Cannot read properties of undefined (reading 'WebView')
at initWebView (client/index.js:35:27)
My code looks like this, unfortunately I don't see any error which is why the error message appears quite unexpectedly.
class WebViewModule {
private WebView: alt.WebView = null;
constructor() {
this.registerEvents();
alt.logDebug('WebViewModule loaded!');
}
registerEvents() {
alt.onServer(ToClientEvents.WebView.initWebView, this.initWebView);
alt.onServer(ToClientEvents.WebView.closeWindow, this.closeWindow);
alt.onServer(ToClientEvents.WebView.openWindow, this.openWindow);
alt.onServer(ToClientEvents.WebView.emitWindow, this.emitWindow);
}
initWebView(debugWebView: boolean) {
if (debugWebView) {
alt.logWarning(this.WebView);
this.WebView = new alt.WebView('http://localhost:8080');
} else {
this.WebView = new alt.WebView(
'http://resource/client/client-dist/index.html',
false
);
}
if (this.WebView) {
this.WebView.focus();
}
}
openWindow(windowName: string, data: object) {
this.WebView.emit('openWindow', windowName, data);
alt.toggleGameControls(false);
alt.showCursor(true);
}
closeWindow() {
this.WebView.emit('closeWindow');
alt.toggleGameControls(true);
alt.showCursor(false);
}
emitWindow(windowName: string, data: object) {
this.WebView.emit('emitWindow', windowName, data);
}
}
Thanks in advance.
