admin管理员组文章数量:1389826
How to serve matrix_sdk_crypto_wasm_bg.wasm in angular v19? The WebAssembly file matrix_sdk_crypto_wasm_bg.wasm
is not being served correctly, resulting in a 404 error. Here are the steps I have taken:
First set up the Angular project: After installing the latest Angular CLI and creating a new project named matrix-client, I installed the wasm library:
$npx @angular/cli@latest new matrix-client --no-ssr
$ng version
Angular CLI: 19.2.4
Node: 20.11.1
Package Manager: npm 10.2.4
$ npm list | grep matrix
├── @matrix-/[email protected]
Create a Crypto Service: Generate a service to handle the Matrix SDK crypto logic:
import { Injectable } from '@angular/core';
import { initAsync, Tracing, LoggerLevel, OlmMachine, UserId, DeviceId } from '@matrix-/matrix-sdk-crypto-wasm';
@Injectable({
providedIn: 'root',
})
export class MatrixCryptoService {
private olmMachine?: OlmMachine;
async initCrypto(userId: string, deviceId: string) {
await initAsync();
new Tracing(LoggerLevel.Trace).turnOn();
this.olmMachine = await OlmMachine.initialize(new UserId(userId), new DeviceId(deviceId));
}
}
Use the Crypto Service in AppComponent: In appponent.ts, call the service to initialize the crypto functionality:
import { Component, OnInit } from '@angular/core';
import { MatrixCryptoService } from './matrix-crypto.service';
import { RouterOutlet } from '@angular/router';
@Component({
selector: 'app-root',
imports: [RouterOutlet],
templateUrl: './appponent.html',
styleUrl: './appponent.css'
})
export class AppComponent implements OnInit {
constructor(private cryptoService: MatrixCryptoService) {}
async ngOnInit() {
await this.cryptoService.initCrypto('@user:matrix', 'DEVICE123');
console.log(this.cryptoService.getOlmMachine());
}
}
Error when serving the application: Upon running the application, you encounter an error in the browser's developer console:
GET http://localhost:4200/@fs/.../matrix-client/.angular/cache/19.2.4/matrix-client/vite/deps/pkg/matrix_sdk_crypto_wasm_bg.wasm [HTTP/1.1 404 Not Found 4ms]
ERROR TypeError: WebAssembly: Response has unsupported MIME type 'text/html; charset=utf-8' expected 'application/wasm'
本文标签: serve matrixsdkcryptowasmbgwasm in angular v19 projectStack Overflow
版权声明:本文标题:serve matrix_sdk_crypto_wasm_bg.wasm in angular v19 project - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744590762a2614476.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论