Cannot read properties of undefined (reading '__wbindgen_free') in calling rust function

Discussão em 'Angular' iniciado por New User, Abril 21, 2025.

  1. New User

    New User Guest

    I am using Rust inside angular as wsam . Installed wsam package cargo install wasm-pack and then created Rust Project using cargo new --lib my-rust-wasm this is my src/lib.rs

    use wasm_bindgen::prelude::*;

    #[wasm_bindgen]
    pub fn greet() -> String {
    "Hello from Rust!".to_string()
    }


    building rust-project using wasm-pack build --target web Now this is my angular appComponent.ts

    import { Component, OnInit } from '@angular/core';
    import { RouterOutlet } from '@angular/router';
    import { greet } from '../assets/pkg/my_rust_wasm.js';
    @Component({
    selector: 'app-root',
    imports: [RouterOutlet],
    templateUrl: './app.component.html',
    styleUrl: './app.component.css'
    })
    export class AppComponent implements OnInit {
    async ngOnInit() {
    console.log(greet());
    }

    private loadWasmModule(path: string): Promise<any> {
    return import(path);
    }
    }

    Continue reading...

Compartilhe esta Página