thaw: Unable to Run Thaw with Leptos-Axum on NixOS
Hello,
I have a bit non-conventional setup with Leptos on NixOS.
I am getting the following error when trying to do cargo run:
[user@host:~/rust/leptos-ssr-thaw]$ cargo run --timings
Compiling leptos-ssr-thaw v0.1.0 (/home/user/rust/leptos-ssr-thaw)
error[E0277]: the trait bound `&fn(ButtonProps) -> impl leptos_dom::IntoView {Button}: ComponentConstructor<_>` is not satisfied
--> src/app.rs:47:5
|
47 | / view! {
48 | | <h1>"Welcome to Leptos!"</h1>
49 | | // <button on:click=on_click>"Click Me: " {count}</button>
50 | |
51 | | <Button variant=ButtonVariant::Primary>"Click me" {count}</Button>
52 | | }
| |_____^ the trait `ComponentConstructor<_>` is not implemented for `&fn(ButtonProps) -> impl leptos_dom::IntoView {Button}`
|
note: required by a bound in `component_view`
--> /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/leptos-0.6.5/src/lib.rs:325:34
|
325 | pub fn component_view<P>(f: impl ComponentConstructor<P>, props: P) -> View {
| ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `component_view`
= note: this error originates in the macro `view` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `fn(ButtonProps) -> impl leptos_dom::IntoView {Button}: leptos::Component<_>` is not satisfied
--> src/app.rs:47:5
|
47 | / view! {
48 | | <h1>"Welcome to Leptos!"</h1>
49 | | // <button on:click=on_click>"Click Me: " {count}</button>
50 | |
51 | | <Button variant=ButtonVariant::Primary>"Click me" {count}</Button>
52 | | }
| |_____^ the trait `leptos::Component<_>` is not implemented for fn item `fn(ButtonProps) -> impl leptos_dom::IntoView {Button}`
|
help: trait impls with same name found
--> /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/leptos-0.5.7/src/lib.rs:309:1
|
309 | impl<F, R> Component<EmptyPropsBuilder> for F where F: FnOnce() -> R {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
310 |
311 | / impl<P, F, R> Component<P> for F
312 | | where
313 | | F: FnOnce(P) -> R,
314 | | P: Props,
| |_____________^
= note: perhaps two different versions of crate `leptos` are being used?
note: required by a bound in `component_props_builder`
--> /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/leptos-0.6.5/src/lib.rs:319:15
|
318 | pub fn component_props_builder<P: PropsOrNoPropsBuilder>(
| ----------------------- required by a bound in this function
319 | _f: &impl Component<P>,
| ^^^^^^^^^^^^ required by this bound in `component_props_builder`
= note: this error originates in the macro `view` (in Nightly builds, run with -Z macro-backtrace for more info)
For more information about this error, try `rustc --explain E0277`.
error: could not compile `leptos-ssr-thaw` (lib) due to 2 previous errors
Here’s src/app.rs:
use crate::error_template::{AppError, ErrorTemplate};
use leptos::*;
use leptos_meta::*;
use leptos_router::*;
use thaw::{Button, ButtonVariant};
#[component]
pub fn App() -> impl IntoView {
// Provides context that manages stylesheets, titles, meta tags, etc.
provide_meta_context();
view! {
// injects a stylesheet into the document <head>
// id=leptos means cargo-leptos will hot-reload this stylesheet
<Stylesheet id="leptos" href="/pkg/leptos-ssr-thaw.css"/>
// sets the document title
<Title text="Welcome to Leptos"/>
// content for this welcome page
<Router fallback=|| {
let mut outside_errors = Errors::default();
outside_errors.insert_with_default_key(AppError::NotFound);
view! {
<ErrorTemplate outside_errors/>
}
.into_view()
}>
<main>
<Routes>
<Route path="" view=HomePage/>
</Routes>
</main>
</Router>
}
}
/// Renders the home page of your application.
#[component]
fn HomePage() -> impl IntoView {
// Creates a reactive value to update the button
let (count, set_count) = create_signal(0);
let on_click = move |_| set_count.update(|count| *count += 1);
view! {
<h1>"Welcome to Leptos!"</h1>
// <button on:click=on_click>"Click Me: " {count}</button>
<Button variant=ButtonVariant::Primary>"Click me" {count}</Button>
}
}
[package]
name = "leptos-ssr-thaw"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["cdylib", "rlib"]
[profile.dev]
incremental = false
debug = 0
lto = "thin"
[dependencies]
axum = { version = "0.7", optional = true }
console_error_panic_hook = "0.1"
leptos = { version = "0.6", features = ["nightly"] }
leptos_axum = { version = "0.6", optional = true }
leptos_meta = { version = "0.6", features = ["nightly"] }
leptos_router = { version = "0.6", features = ["nightly"] }
tokio = { version = "1", features = ["rt-multi-thread"], optional = true }
tower = { version = "0.4", optional = true }
tower-http = { version = "0.5", features = ["fs"], optional = true }
wasm-bindgen = "=0.2.91"
thiserror = "1"
tracing = { version = "0.1", optional = true }
http = "1"
thaw = { version = "0.1.10", features = ["csr", "ssr"] }
[features]
hydrate = ["leptos/hydrate", "leptos_meta/hydrate", "leptos_router/hydrate"]
ssr = [
"dep:axum",
"dep:tokio",
"dep:tower",
"dep:tower-http",
"dep:leptos_axum",
"leptos/ssr",
"leptos_meta/ssr",
"leptos_router/ssr",
"dep:tracing",
]
# Defines a size-optimized profile for the WASM bundle in release mode
[profile.wasm-release]
inherits = "release"
opt-level = 'z'
lto = true
codegen-units = 1
panic = "abort"
incremental = false
[package.metadata.leptos]
# The name used by wasm-bindgen/cargo-leptos for the JS/WASM bundle. Defaults to the crate name
output-name = "leptos-ssr-thaw"
# The site root folder is where cargo-leptos generate all output. WARNING: all content of this folder will be erased on a rebuild. Use it in your server setup.
site-root = "target/site"
# The site-root relative folder where all compiled output (JS, WASM and CSS) is written
# Defaults to pkg
site-pkg-dir = "pkg"
# [Optional] The source CSS file. If it ends with .sass or .scss then it will be compiled by dart-sass into CSS. The CSS is optimized by Lightning CSS before being written to <site-root>/<site-pkg>/app.css
style-file = "style/main.scss"
# Assets source dir. All files found here will be copied and synchronized to site-root.
# The assets-dir cannot have a sub directory with the same name/path as site-pkg-dir.
#
# Optional. Env: LEPTOS_ASSETS_DIR.
assets-dir = "public"
# The IP and port (ex: 127.0.0.1:3000) where the server serves the content. Use it in your server setup.
site-addr = "127.0.0.1:3000"
# The port to use for automatic reload monitoring
reload-port = 3001
# [Optional] Command to use when running end2end tests. It will run in the end2end dir.
# [Windows] for non-WSL use "npx.cmd playwright test"
# This binary name can be checked in Powershell with Get-Command npx
end2end-cmd = "npx playwright test"
end2end-dir = "end2end"
# The browserlist query used for optimizing the CSS.
browserquery = "defaults"
# Set by cargo-leptos watch when building with that tool. Controls whether autoreload JS will be included in the head
watch = false
# The environment Leptos will run in, usually either "DEV" or "PROD"
env = "DEV"
# The features to use when compiling the bin target
#
# Optional. Can be over-ridden with the command line parameter --bin-features
bin-features = ["ssr"]
# If the --no-default-features flag should be used when compiling the bin target
#
# Optional. Defaults to false.
bin-default-features = false
# The features to use when compiling the lib target
#
# Optional. Can be over-ridden with the command line parameter --lib-features
lib-features = ["hydrate"]
# If the --no-default-features flag should be used when compiling the lib target
#
# Optional. Defaults to false.
lib-default-features = false
# The profile to use for the lib target when compiling for release
#
# Optional. Defaults to "release".
lib-profile-release = "wasm-release"
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 17 (2 by maintainers)
So - I got around it. Looks like the core of it was that I needed to update my nightly rust binaries so that Axum 0.7.5 would build (uses diagnostic macro); once that built (which I missed in previous attempts) seems like everything else fell into place. Rust newbie and still feeling my way around. Apologies for wasting your time here. Appreciate the prompt response. Looking forward to using these components too. 😃