OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

ReferenceError: print_text is not defined [WASM]

  • Thread starter Thread starter mmmmm
  • Start date Start date
M

mmmmm

Guest
Just a beginner writing a very simple rust program to build a lib

Code:
pub use wasm_bindgen::prelude::*;

#[wasm_bindgen]
pub struct SomeStruct {
}

#[wasm_bindgen]
impl SomeStruct {
    
    #[wasm_bindgen(constructor)]
    pub fn new() -> SomeStruct {
        SomeStruct { }
    }

    pub fn print_text() {
        println!("Text to Print");
    }
}

index.js

Code:
import { SomeStruct } from './pkg';
document.write(print_text());

when running

Code:
npm run serve

getting

Code:
Uncaught runtime errors:

ERROR
print_text is not defined
ReferenceError: print_text is not defined
    at eval (webpack:///./index.js?:7:10)

I'm new to both Rust and JS, and can't understand exactly where I am missing

In pkg folder, I have files with following names

Code:
index.d
index.js
index_bg.js
index_bg.wasm
index_bg.wasm.d
package

<p>Just a beginner writing a very simple rust program to build a lib</p>
<pre><code>
pub use wasm_bindgen::prelude::*;

#[wasm_bindgen]
pub struct SomeStruct {
}

#[wasm_bindgen]
impl SomeStruct {

#[wasm_bindgen(constructor)]
pub fn new() -> SomeStruct {
SomeStruct { }
}

pub fn print_text() {
println!("Text to Print");
}
}

</code></pre>
<p>index.js</p>
<pre><code>import { SomeStruct } from './pkg';
document.write(print_text());
</code></pre>
<p>when running</p>
<pre><code>npm run serve
</code></pre>
<p>getting</p>
<pre><code>Uncaught runtime errors:

ERROR
print_text is not defined
ReferenceError: print_text is not defined
at eval (webpack:///./index.js?:7:10)
</code></pre>
<p>I'm new to both Rust and JS, and can't understand exactly where I am missing</p>
<p>In <strong>pkg</strong> folder, I have files with following names</p>
<pre><code>index.d
index.js
index_bg.js
index_bg.wasm
index_bg.wasm.d
package
</code></pre>
 

Latest posts

Top