Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to resolve: use of undeclared crate or module specta_util in Tauri v2.2.0 #305

Open
lanyeeee opened this issue Jan 4, 2025 · 0 comments

Comments

@lanyeeee
Copy link

lanyeeee commented Jan 4, 2025

Reproduce (step by step):

1. Create a new Tauri project:

pnpm create tauri-app@latest
✔ Project name · tauri-app
✔ Identifier · com.tauri-app.app
✔ Choose which language to use for your frontend · TypeScript / JavaScript - (pnpm, yarn, npm, bun)
✔ Choose your package manager · pnpm
✔ Choose your UI template · Vanilla
✔ Choose your UI flavor · TypeScript

2. Add specta:

[package]
name = "tauri-app"
version = "0.1.0"
description = "A Tauri App"
authors = ["you"]
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
# The `_lib` suffix may seem redundant but it is necessary
# to make the lib name unique and wouldn't conflict with the bin name.
# This seems to be only an issue on Windows, see https://github.com/rust-lang/cargo/issues/8519
name = "tauri_app_lib"
crate-type = ["staticlib", "cdylib", "rlib"]

[build-dependencies]
tauri-build = { version = "2", features = [] }

[dependencies]
tauri = { version = "2", features = [] }
tauri-plugin-opener = "2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"

+ specta = { version = "2.0.0-rc" }
+ tauri-specta = { version = "2.0.0-rc", features = ["derive", "typescript"] }
+ specta-typescript = { version = "0.0.7" }

3. Modify lib.rs to:

use serde::{Deserialize, Serialize};
use specta::Type;
use tauri::Wry;

// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
#[tauri::command]
#[specta::specta]
fn greet(name: &str) -> String {
    format!("Hello, {}! You've been greeted from Rust!", name)
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, Type)]
pub struct TestStruct {
    pub field: String,
}

#[tauri::command]
#[specta::specta]
fn test() -> TestStruct {
    TestStruct {
        field: "Hello, World!".to_string(),
    }
}

#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
    let builder = tauri_specta::Builder::<Wry>::new()
        .commands(tauri_specta::collect_commands![greet])
        .events(tauri_specta::collect_events![]);

    #[cfg(debug_assertions)]
    builder
        .export(
            specta_typescript::Typescript::default()
                .bigint(specta_typescript::BigIntExportBehavior::Number)
                .formatter(specta_typescript::formatter::prettier)
                .header("// @ts-nocheck"),
            "../src/bindings.ts",
        )
        .expect("Failed to export typescript bindings");

    tauri::Builder::default()
        .plugin(tauri_plugin_opener::init())
        .invoke_handler(builder.invoke_handler())
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

4. You will see the error message:

error[E0433]: failed to resolve: use of undeclared crate or module `specta_util`
  --> src\lib.rs:12:68
   |
12 | #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, Type)]
   |                                                                    ^^^^ use of undeclared crate or module `specta_util`

I noticed that the dependencies in Tauri v2.2.0 include specta-util, but Tauri v2.1.1 does not have specta-util.
Additionally, I have a Tauri v2.1.1 project that can use specta without any issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant