Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Module doesn't have export __wbindgen_describe___wbg_f_alert_alert_n" #309

Closed
steveklabnik opened this issue Jun 25, 2018 · 10 comments
Closed
Labels

Comments

@steveklabnik
Copy link

steveklabnik commented Jun 25, 2018

Code:

> cat .\src\lib.rs
#![feature(proc_macro, wasm_import_module, wasm_custom_section)]

extern crate wasm_bindgen;

use wasm_bindgen::prelude::*;

#[wasm_bindgen]
extern {
    fn alert(s: &str);
}

#[wasm_bindgen]
pub fn greet(name: &str) {
    alert(&format!("Hello, {}!", name));
}

Cargo.toml:

[package]
name = "wasmpacktest"
version = "0.1.0"
authors = ["steveklabnik <steve@steveklabnik.com>"]

[lib]
crate-type = ["cdylib"]

[dependencies]
wasm-bindgen = "0.2"

When I invoke wasm-bindgen through wasm-pack...:

> wasm-pack init

  [1/8] Checking crate configuration...
  [2/8] Adding WASM target...
  [3/8] Compiling to WASM...
  [4/8] Creating a pkg directory...
  [5/8] Writing a package.json...
  :-) [WARN]: Field description is missing from Cargo.toml. It is not necessary, but recommended
  :-) [WARN]: Field repository is missing from Cargo.toml. It is not necessary, but recommended
  :-) [WARN]: Field license is missing from Cargo.toml. It is not necessary, but recommended
  [6/8] Copying over your README...
  :-) [WARN]: origin crate has no README
  [7/8] Installing WASM-bindgen...
| [8/8] Running WASM-bindgen...
wasm-bindgen failed to execute properly. stderr:

thread 'main' panicked at 'failed to run export: Function("Module doesn\'t have export __wbindgen_describe___wbg_f_alert_alert_n")', libcore\result.rs:945:5
note: Run with `RUST_BACKTRACE=1` for a backtrace.

rustc version:

> rustc --version
rustc 1.28.0-nightly (01cc982e9 2018-06-24)

Any ideas what's wrong here?

@wismer
Copy link
Contributor

wismer commented Jun 25, 2018

@steveklabnik I wonder if it has to do with the extern func declaration? I'm accustomed to seeing examples having the functions exposed with pub

steveklabnik added a commit to steveklabnik/wasm-pack that referenced this issue Jun 25, 2018
This won't compile if it isn't pub!

Fixes rustwasm/wasm-bindgen#309
@steveklabnik
Copy link
Author

That is totally it! I've sent a docs PR upstream.

@fitzgen
Copy link
Member

fitzgen commented Jun 25, 2018

If the use of the thing is in the same crate (as is the case here), then it shouldn't need the pub... Not sure what is going on here.

@fitzgen
Copy link
Member

fitzgen commented Jun 26, 2018

I still think it is a bug that it doesn't work without pub.

@turboladen
Copy link

For future lurkers... I ran into this same thing where I was in business with:

// src/lib.rs
pub other_module;

// src/other_module.rs
#[wasm_bindgen]
// stuff

...but as soon as I removed the pub from the module declaration in lib.rs, I started getting the same as reported here. Had me scratching my head because all of the things in other_module were marked pub. Once I made made the module pub again I was 👍 .

@alexcrichton
Copy link
Contributor

@turboladen I think that issue is #201

@alexcrichton
Copy link
Contributor

@steveklabnik hm I'm a little confused and I wonder if this could be a roundabout version mismatch or wasm-pack bug? We have an example in this repository with your exact example above, and it's tested to work on CI

If you check out the master branch of this repo does the example work? Or does your installed tool work? Do you know what version was installed?

@turboladen
Copy link

Ah, thanks @alexcrichton !

@alexcrichton
Copy link
Contributor

Hm I've also tried out the instructions in the OP and can't reproduce :(

@alexcrichton
Copy link
Contributor

I'm gonna close this as this is likely a dupe of #201, but if not I can always reopen!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants