#Rust Wasm Plugin - `cannot find definition for import __wbindgen_placeholder__`

20 messages · Page 1 of 1 (latest)

granite oxide
#

Hi!

I'm working on a project that builds a gantt chart, the heavy lifting here is offloaded to a rust wasm plugin.

Now, trying to import this plugin in typst document and I hit the following error when compiling PDF:

error: cannot find definition for import __wbindgen_placeholder__::__wbindgen_describe with type Func(FuncType { params: [I32], results: [] })
  ┌─ example.typ:3:31
  │
3 │   let timeline_plugin = plugin("./target/wasm32-unknown-unknown/release/gantt_purely_rust.wasm")
  │                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I have searched discord and found people are experiencing similar but not exactly the same issues, and I cannot troubleshoot on my own.

I use NixOS, and a self-contained development flake with dependencies is provided. I've tested the example in https://github.com/astrale-sharp/wasm-minimal-protocol/tree/master/examples/hello_rust with the very flake and it did compile both the plugin and the typst document, so I presume I've set the dependencies up properly.

The entire project is available at https://github.com/disbolog/wasm-typst

Thank you!

CC: @clever seal @patent oracle

GitHub

Contribute to astrale-sharp/wasm-minimal-protocol development by creating an account on GitHub.

GitHub

Contribute to disbolog/wasm-typst development by creating an account on GitHub.

sullen onyx
#

You've not attached #[wasm_func] to your function. Does adding that maybe help?

granite oxide
#

Let me see

patent oracle
#

At least one of your dependencies seems to be using the wasm-bindgen crate which makes the resulting wasm easily usable in browser contexts with JavaScript. This however requires the runtime to provide certain functions, which is only (?) done in the JavaScript case, thus breaking in all other cases including typst. To fix this, you will have to find out (e.g. using cargo tree) which dependencies are using that crate and hope that there is a way to disable it (probably using a cargo feature).

granite oxide
#

@patent oracle

$ cargo tree
gantt-purely-rust v0.1.0 (/home/user/2025-05-11-gantt-purely-rust)
├── chrono v0.4.41
│   ├── iana-time-zone v0.1.63
│   ├── num-traits v0.2.19
│   │   [build-dependencies]
│   │   └── autocfg v1.4.0
│   └── serde v1.0.219
│       └── serde_derive v1.0.219 (proc-macro)
│           ├── proc-macro2 v1.0.95
│           │   └── unicode-ident v1.0.18
│           ├── quote v1.0.40
│           │   └── proc-macro2 v1.0.95 (*)
│           └── syn v2.0.101
│               ├── proc-macro2 v1.0.95 (*)
│               ├── quote v1.0.40 (*)
│               └── unicode-ident v1.0.18
├── ciborium v0.2.2
│   ├── ciborium-io v0.2.2
│   ├── ciborium-ll v0.2.2
│   │   ├── ciborium-io v0.2.2
│   │   └── half v2.6.0
│   │       └── cfg-if v1.0.0
│   └── serde v1.0.219 (*)
├── indoc v2.0.6 (proc-macro)
├── serde v1.0.219 (*)
└── wasm-minimal-protocol v0.1.0 (proc-macro) (https://github.com/astrale-sharp/wasm-minimal-protocol.git#03086a8f)
    ├── proc-macro2 v1.0.95 (*)
    ├── quote v1.0.40 (*)
    └── venial v0.5.0
        ├── proc-macro2 v1.0.95 (*)
        └── quote v1.0.40 (*)
#

Does not seem to be any wasm-bindgen dependency

granite oxide
patent oracle
#

Can you run this

cargo tree --target wasm32-unknown-unknown -i wasm-bindgen
granite oxide
#

ok:

├── chrono v0.4.41
│   └── gantt-purely-rust v0.1.0 (/home/user/2025-05-11-gantt-purely-rust)
└── js-sys v0.3.77
    └── chrono v0.4.41 (*)
patent oracle
granite oxide
#

Does that mean I either remove chrono, or play with feature toggles?

patent oracle
#

You can check if there is a feature in Chrono that disables wasm-bindgen

#

Ok there seems to be a wasmbind feature which is enabled by default

granite oxide
#

I believe there is : wasmbind: Interface with the JS Date API for the wasm32 target.

#

Let me just try use features with default=false, but include the rest

#

@patent oracle okay, we're moving 😅 now this:

error: plugin errored with: Semantic(None, "input contains invalid characters")
  ┌─ example.typ:5:19
  │  
5 │       let timeline = timeline_plugin.create_timeline_wasm(cbor.encode((
  │ ╭────────────────────^
6 │ │         start_date: datetime(year: 2024, month: 1, day: 1),
7 │ │         end_date: datetime(year: 2024, month: 3, day: 31),
8 │ │         show_weekends: true,
9 │ │     )))
  │ ╰───────^
#

Okay, I was able to fix this too, this is now purely rust thingy

#

Thank you both @patent oracle @sullen onyx 👍

sullen onyx
#

I contributed only a wrong guess, but nice to see the issue is fixed :D