openimsdk / open-im-sdk-web-wasm

JS SDK for OpenIM Web use by Webassembly of go
https://openim.io
Apache License 2.0
35 stars 49 forks source link

[BUG] MainContentLayout-868bfdc8.js:1 TypeError: window.commonEventFunc is not a function at We.login (open-im-sdk-wasm-3b339908.js:1:25495) #128

Closed wang22290 closed 2 months ago

wang22290 commented 2 months ago

OpenIM Server Version

3.8.0

Operating System and CPU Architecture

macOS (ARM)

Deployment Method

Source Code Deployment

Bug Description and Steps to Reproduce

image

I’m using an Electron demo that references open-im-sdk-web-wasm 3.8.0. When running the project with npm run dev, no errors occur. However, after packaging the project into a .app file, I get the following error: TypeError: window.commonEventFunc is not a function at We.login (open-im-sdk-wasm-3b339908.js:1:25495), and I’m unable to log in to IMSDK.”

Screenshots Link

No response

Bloomingg commented 2 months ago

Did you move the openIM.wasm file?

wang22290 commented 2 months ago

Did you move the openIM.wasm file?

No ,I am using an Electron demo and using Electron Forge to package the project without changing any code.

Bloomingg commented 2 months ago

So you are not using the official demo, maybe you can refer to the official electon demo. Your problem is because the openIM.wasm file is not loaded correctly.

wang22290 commented 2 months ago

So you are not using the official demo, maybe you can refer to the official electon demo. Your problem is because the openIM.wasm file is not loaded correctly.

I didn't understand what you meant. I used the Electron Demo on GitHub, but I just packaged it into an. app file using the Electron Forge tool and installed it on my Mac computer,

image
Bloomingg commented 2 months ago

You need to make sure that the packaged file can still be loaded correctly into the wasm file. In fact, the dev and prod environments are somewhat different. For example, the following processing is done in openim-electron-demo. You may need to check your actual import path.

wang22290 commented 2 months ago

You need to make sure that the packaged file can still be loaded correctly into the wasm file. In fact, the dev and prod environments are somewhat different. For example, the following processing is done in openim-electron-demo. You may need to check your actual import path.

I modified the path as you suggested, but still reported the same error,

image
Bloomingg commented 2 months ago

actually, I don’t mean to ask you to change the path to the same path as mine… Because the basic framework structure of your project may not be the same as the demo, the key point is how to find the correct import path that belongs to your project structure.

wang22290 commented 2 months ago

actually, I don’t mean to ask you to change the path to the same path as mine… Because the basic framework structure of your project may not be the same as the demo, the key point is how to find the correct import path that belongs to your project structure.

I have discovered another issue where the openIMwasm file in the dist file generated by my build cannot be properly packaged into the. app project, as shown in the picture. I have tried to modify the packaging configuration, but it still does not take effect

image image

image

PineSongCN commented 2 months ago

我这边是网页版报了类似的错误,原因是nginx的mine.types缺少wasm的类型,没有正确识别解析wasm文件导致的。 https://juejin.cn/post/7410710728783298611

OpenIM-Robot commented 2 months ago

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


I reported a similar error on the web version. The reason is that nginx's mine.types lacks the wasm type and does not correctly identify and parse the wasm file. https://juejin.cn/post/7410710728783298611

wang22290 commented 2 months ago

actually, I don’t mean to ask you to change the path to the same path as mine… Because the basic framework structure of your project may not be the same as the demo, the key point is how to find the correct import path that belongs to your project structure.

@Bloomingg

I modified the package directory of openIM.wasm. I can get the correct address directly under the Resources file, but window.commonEventFunc is not a function still exists.

I found that Electron may have file path problems, especially in production environments, where file:// protocol paths cannot be loaded directly using the browser environment.

Is this error related to this?

image image

Bloomingg commented 2 months ago

you can update you sdk and try again.

npm i @openim/wasm-client-sdk@latest
wang22290 commented 2 months ago

you can update you sdk and try again.

npm i @openim/wasm-client-sdk@latest

@Bloomingg

I used the latest version of openIMSDK ("@openim/wasm-client-sdk": "^3.8.1",) and the Electron Demo from github, and packaged it into an app file with Electron Forge, but still got an error.

image

wang22290 commented 2 months ago

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿

I reported a similar error on the web version. The reason is that nginx's mine.types lacks the wasm type and does not correctly identify and parse the wasm file. https://juejin.cn/post/7410710728783298611

我使用的是Electron Demo。我没有理解这个配置该如何修改

Bloomingg commented 2 months ago

the latest version is 3.8.2-beta.2