koute / stdweb

A standard library for the client-side Web

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

no possible use document

dancespiele opened this issue · comments

I use stdweb with parcel and parcel-plugin-cargo-web and when I want to do something with document for example:

#[macro_use]
extern crate stdweb;

use stdweb::traits::*;
use stdweb::{js_export, web::{document}};

#[js_export]
pub fn greet(name: &str) {
    let element = document().create_element("h1").unwrap();
    element.set_text_content(name);
    let body = document().body().unwrap();
    body.append_child(&element);
}

I get this error:

Error loading Rust wasm module 'wasm_modules': LinkError: "import object field '__cargo_web_snippet_ab05f53189dacccf2d365ad26daa407d4f7abea9' is not a Function"
    __initialize http://localhost:9000/src.f10117fe.js:505
    __initialize http://localhost:9000/src.f10117fe.js:501
    exports http://localhost:9000/src.f10117fe.js:1099
src.f10117fe.js:510:11
LinkError: import object field '__cargo_web_snippet_ab05f53189dacccf2d365ad26daa407d4f7abea9' is not a Function src.f10117fe.js:505:16

however this code works

#[macro_use]
extern crate stdweb;

use stdweb::{js_export};

#[js_export]
pub fn greet(name: &str) {
    js! {
        alert(@{name});
    }
}

ok I know what exactly is the issue. When I change something from the js_export function I have to start the parcel again to make it works. This issue come from the plugin, I will write a ticket there.