# BUG: Compilation errors when trying to add ic-agent to an Axum project. Error attached

**URL:** <https://forum.dfinity.org/t/bug-compilation-errors-when-trying-to-add-ic-agent-to-an-axum-project-error-attached/24671>\
**Category:** Rust\
**Created:** [November 14, 2023, 9:56am UTC](https://forum.dfinity.org/t/bug-compilation-errors-when-trying-to-add-ic-agent-to-an-axum-project-error-attached/24671 "2023-11-14T09:56:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![saikatdas0790](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/saikatdas0790/32/17147_2.png) [@saikatdas0790](https://forum.dfinity.org/u/saikatdas0790)\
**Post date:** [November 14, 2023, 9:56am UTC](https://forum.dfinity.org/t/bug-compilation-errors-when-trying-to-add-ic-agent-to-an-axum-project-error-attached/24671/1 "2023-11-14T09:56:38Z")

</div>

Here is the error I’m seeing when I add ic-agent to a Axum project:

 ![image](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/2X/1/1239b7d42539c34c1494ba220e9a68182e2d79e5.png)

The intent is to be able to call into the IC as a data layer from an off-chain server.

Here is a minimal reproduction:

> **[GitHub - saikatdas0790/minimal-reproduction-add-agent-rs-to-cargo-leptos-project](https://github.com/saikatdas0790/minimal-reproduction-add-agent-rs-to-cargo-leptos-project)**
>
> Contribute to saikatdas0790/minimal-reproduction-add-agent-rs-to-cargo-leptos-project development by creating an account on GitHub.

Thoughts?

---

<div class="post-metadata">

**Author:** ![lwshang](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/lwshang/32/3394_2.png) [@lwshang](https://forum.dfinity.org/u/lwshang)\
**Post date:** [November 14, 2023, 2:45pm UTC](https://forum.dfinity.org/t/bug-compilation-errors-when-trying-to-add-ic-agent-to-an-axum-project-error-attached/24671/2 "2023-11-14T14:45:45Z")

</div>

Just checked the source code [here](https://github.com/dfinity/agent-rs/blob/3cb1c46a4bf951060f97eb10d5347058a5b364bf/ic-agent/src/agent/mod.rs#L684-L705).

We have conditional compilation for the match pattern `Some(duration)`:

- If the target is not `wasm`
- If the target is `wasm` **AND** the `wasm-bindgen` feature is **on**

There can be a case that is not covered: the target is `wasm` **AND** the `wasm-bindgen` feature is **off**.

Are you embedding Rust agent in Wasm? If so, turning on `wasm-bindgen` feature should make it work.

P.S. IMO, this is indeed a Rust agent issue. It should compile for wasm when the feature is off.

---

<div class="post-metadata">

**Author:** ![saikatdas0790](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/saikatdas0790/32/17147_2.png) [@saikatdas0790](https://forum.dfinity.org/u/saikatdas0790)\
**Post date:** [November 14, 2023, 3:40pm UTC](https://forum.dfinity.org/t/bug-compilation-errors-when-trying-to-add-ic-agent-to-an-axum-project-error-attached/24671/3 "2023-11-14T15:40:07Z")

</div>

@lwshang

For the above error, I just added the crate to a Leptos project.

I haven’t imported/added any `use` statements for the error to show up.

I’m not completely sure about this

> [@lwshang](#):
>
> Are you embedding Rust agent in Wasm?

From what I’m aware, Leptos compiles to 2 different outputs, an Axum server binary that is run on the server and performs SSR and another WASM bundle that is used when hydrating on the client browser and takes over interactivity. The agent will be used in both places is what I intend to do to fetch data from the IC and prerender pages on the server and serve to clients for fast initial page loads and then use the agent for further data loading on the client for subsequent interactivity

Here’s some more context from the Leptos repo

> **[GitHub - leptos-rs/cargo-leptos: Build tool for Leptos (Rust)](https://github.com/leptos-rs/cargo-leptos#build-features)**
>
> Build tool for Leptos (Rust). Contribute to leptos-rs/cargo-leptos development by creating an account on GitHub.

> When building with cargo-leptos, the frontend, library package, is compiled into wasm using target `wasm-unknown-unknown` and the features `--no-default-features --features=hydrate` The server binary is compiled with the features `--no-default-features --features=ssr`

The cargo build parameters look something like this when building:  
 ![image](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/2X/a/a4d315633f9e117ccfece2684c3f1153e5152af6.png)

Let me know if that was helpful or if there’s any more context I can provide 🙂

---

<div class="post-metadata">

**Author:** ![lwshang](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/lwshang/32/3394_2.png) [@lwshang](https://forum.dfinity.org/u/lwshang)\
**Post date:** [November 14, 2023, 4:23pm UTC](https://forum.dfinity.org/t/bug-compilation-errors-when-trying-to-add-ic-agent-to-an-axum-project-error-attached/24671/4 "2023-11-14T16:23:52Z")

</div>

In your `Cargo.toml`, change the line of `ic-agent` into:

```toml
ic-agent = { version = "0.30.0", features = ["wasm-bindgen"] }

```

---

<div class="post-metadata">

**Author:** ![saikatdas0790](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/saikatdas0790/32/17147_2.png) [@saikatdas0790](https://forum.dfinity.org/u/saikatdas0790)\
**Post date:** [November 14, 2023, 4:34pm UTC](https://forum.dfinity.org/t/bug-compilation-errors-when-trying-to-add-ic-agent-to-an-axum-project-error-attached/24671/5 "2023-11-14T16:34:07Z")

</div>

Yes, I believe that worked. Thank you so much
