AscendingCreations / AxumSession

Axum Session Management Libraries that use Sqlx
MIT License
147 stars 32 forks source link

does not work with cargo leptos #86

Open KhaledHosseini opened 3 months ago

KhaledHosseini commented 3 months ago

when it is added to leptos project, and after running cargo leptos watch, the following error rises:

Compiling mio v0.8.11
 unresolved import `crate::sys::IoSourceState`
  --> /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/mio-0.8.11/src/io_source.rs:12:5
   |
12 | use crate::sys::IoSourceState;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^ no `IoSourceState` in `sys`

error[E0432]: unresolved import `crate::sys::tcp`
  --> /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/mio-0.8.11/src/net/tcp/listener.rs:15:17
   |
15 | use crate::sys::tcp::{bind, listen, new_for_addr};
   |                 ^^^ could not find `tcp` in `sys`

error[E0432]: unresolved import `crate::sys::tcp`
  --> /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/mio-0.8.11/src/net/tcp/stream.rs:13:17
   |
13 | use crate::sys::tcp::{connect, new_for_addr};
   |                 ^^^ could not find `tcp` in `sys`

error[E0433]: failed to resolve: could not find `Selector` in `sys`
   --> /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/mio-0.8.11/src/poll.rs:312:18
    |
312 |             sys::Selector::new().map(|selector| Poll {
    |                  ^^^^^^^^ could not find `Selector` in `sys`

error[E0433]: failed to resolve: could not find `event` in `sys`
  --> /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/mio-0.8.11/src/event/event.rs:24:14
   |
24 |         sys::event::token(&self.inner)
   |              ^^^^^ could not find `event` in `sys`

Any suggestion on how to resolve this?

genusistimelord commented 3 months ago

I have asked benwise to take a look at this issue. As I have no idea why this is occurring. But from the Error, it seems to be some issue with Mio? Are you using Axum with Leptos? If not, my Session library will not currently work for anything but Axum. I have been planning to expand access to other systems that Leptos supports, but have not found the time to get around to it yet.

KhaledHosseini commented 3 months ago

I have asked benwise to take a look at this issue. As I have no idea why this is occurring. But from the Error, it seems to be some issue with Mio? Are you using Axum with Leptos? If not, my Session library will not currently work for anything but Axum. I have been planning to expand access to other systems that Leptos supports, but have not found the time to get around to it yet.

Yes, I use axum. I created my project using: cargo leptos new --git leptos-rs/start-axum.

KhaledHosseini commented 3 months ago

For anyone who comes up with this problem, you can solve it by making the crate optional inside leptos project Cargo.toml. many crates have limited WASM support and you need to make them optional and only enable them in the server feature(ssr). so instead of

axum_session = { version = "0.14.0", features = ["advanced"] }
axum_session_auth = { version = "0.14.0", features = ["advanced"]}
axum_session_sqlx = { version= "0.1.0"}

use the following: (add optional=true):

axum_session = { version = "0.14.0", features = ["advanced"], optional = true }
axum_session_auth = { version = "0.14.0", features = ["advanced"], optional = true}
axum_session_sqlx = { version= "0.1.0", optional = true}

[features]
hydrate = ["leptos/hydrate", "leptos_meta/hydrate", "leptos_router/hydrate"]
ssr = [
    "dep:axum",
    "dep:tokio",
    "dep:sqlx",
    "dep:axum_session",
    "dep:axum_session_auth",
    "dep:axum_session_sqlx",
    "dep:tower",
    "dep:tower-http",
    "dep:leptos_axum",
    "leptos/ssr",
    "leptos_meta/ssr",
    "leptos_router/ssr",
    "dep:tracing",
]
genusistimelord commented 3 months ago

ahh so that was the issue. Thank you for letting us know. We will leave this Open for other people to See the answer too.