error[E0432]: unresolved import `tauri::api::dialog`

Hi everyone, the compiler gave me this error.
What am I doing wrong ?

 use tauri::api::dialog::confirm;


// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), 
windows_subsystem = "windows"
)]

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

#[tauri::command]
fn set_name(name: &str) -> String {
    format!("name : {}! ", name)
} 

fn main() {
    tauri::Builder::default()
        .on_window_event(|event|{
            match event.event() {
                tauri::WindowEvent::CloseRequested{ api,..} =>{
                    api.prevent_close();
                    let window = event.window().clone();
                    confirm(Some(&event.window()),"Close"," Close?", move| answer|{
                        if answer{
                            window.close();
                        }
                    })
                },
                _ => {} 
            }
        })
        .invoke_handler(tauri::generate_handler![greet,set_name])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
} 

error[E0432]: unresolved import tauri::api::dialog
--> src\main.rs:2:17
|
2 | use tauri::api::dialog::confirm;
| ^^^^^^ could not find dialog in api

For more information about this error, try rustc --explain E0432.
error: could not compile emanpro (bin "emanpro") due to 2 previous errors

this is on win10 with tauri 1.6.1
IDE:vscode
compile error

tauri1.6.1 Examples:
https://docs.rs/tauri/1.6.1/tauri/api/dialog/fn.confirm.html

How is the dependency on tauri declared in your Cargo.toml?

[package]
name = "emanpro"
version = "0.0.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

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

[dependencies]
tauri = { version = "1", features = ["shell-open"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"

[features]
# This feature is used for production builds or when a dev server is not specified, DO NOT REMOVE!!
custom-protocol = ["tauri/custom-protocol"]

Check out the yellow box in the documentation.

Available on desktop and crate feature dialog only.

You need to add the dialog feature.

cargo add tauri -F dialog
2 Likes

Thank you! It working! :+1:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.