rust

Unresolved import `self::ssr` in Leptos example


I'm looking at the leptos example 'todo_app_sqlite_axum'.

https://github.com/leptos-rs/leptos/tree/main/examples/todo_app_sqlite_axum

In todo.rs, the function 'get_todos' has an import statement

use self::ssr::*;

error is

error[E0432]: unresolved import `self::ssr`
  --> src/todo.rs:96:15
   |
96 |     use self::ssr::*;
   |               ^^^ could not find `ssr` in `self`


Solution

  • todo.rs includes a ssr module, but it is feature-gated by "ssr":

    #[cfg(feature = "ssr")]
    pub mod ssr {
        // use http::{header::SET_COOKIE, HeaderMap, HeaderValue, StatusCode};
        use leptos::server_fn::ServerFnError;
        use sqlx::{Connection, SqliteConnection};
    
        pub async fn db() -> Result<SqliteConnection, ServerFnError> {
            Ok(SqliteConnection::connect("sqlite:Todos.db").await?)
        }
    }
    

    The #[server] functions that use self::ssr::* are not similarly feature-gated.

    Anyway, you should be able to run the example by enabling the feature:

    cargo run --example todo_app_sqlite_axum --features ssr
    

    There are some SSR notes in the examples folder but I would probably file an issue.