tauri icon indicating copy to clipboard operation
tauri copied to clipboard

[bug] `tauri_plugin_store` doesn't work with the Tauri 2 alpha

Open Zertz opened this issue 2 years ago • 8 comments

Describe the bug

tauri_plugin_store doesn't work with the Tauri 2 alpha.

Reproduction

use tauri;
use tauri_plugin_store::PluginBuilder;

fn main() {
  tauri::Builder
    ::default()
    .plugin(PluginBuilder::default().build()) // ❌
    .run(tauri::generate_context!())
    .expect("error while running tauri application");
}

Expected behavior

I expected it to compile just like it used to.

Platform and versions

yarn run v1.22.19
$ tauri info

Environment
  › OS: Mac OS 13.0.1 X64
  › Node.js: 16.18.1
  › npm: 8.19.2
  › pnpm: 7.19.0
  › yarn: 1.22.19
  › rustup: 1.25.1
  › rustc: 1.66.0
  › cargo: 1.66.0
  › Rust toolchain: stable-aarch64-apple-darwin

Packages
  › @tauri-apps/cli [NPM]: 2.0.0-alpha.1
  › @tauri-apps/api [NPM]: 2.0.0-alpha.0
  › tauri [RUST]: 2.0.0-alpha.2 (1.2.0, 2.0.0-alpha.2),
  › tauri-build [RUST]: 2.0.0-alpha.0,
  › tao [RUST]: 0.15.4,
  › wry [RUST]: no manifest (0.22.1, 0.23.4),

App
  › build-type: bundle
  › CSP: unset
  › distDir: ../dist
  › devPath: http://localhost:5173/
  › framework: React
  › bundler: Vite

App directory structure
  ├─ test
  ├─ dist
  ├─ node_modules
  ├─ www
  ├─ .github
  ├─ src-tauri
  ├─ build
  ├─ .git
  ├─ .vscode
  └─ src
✨  Done in 6.65s.

Stack trace

tauri_plugin_store
pub struct PluginBuilder
2 implementations

the trait bound `tauri::plugin::TauriPlugin<_>: Plugin<tauri_runtime_wry::Wry<EventLoopMessage>>` is not satisfied
the trait `Plugin<R>` is implemented for `TauriPlugin<R, C>`rustcClick for full compiler diagnostic
main.rs(580, 6): required by a bound introduced by this call
app.rs(1203, 20): required by a bound in `tauri::Builder::<R>::plugin`

Additional context

No response

Zertz avatar Dec 30 '22 19:12 Zertz

I think I have the same issue on 1.2.3. I'm trying to use the sql plugin and followed the installation steps described there.

Reproduction

#![cfg_attr(
  all(not(debug_assertions), target_os = "windows"),
  windows_subsystem = "windows"
)]

fn main() {
  tauri::Builder::default()
    .plugin(tauri_plugin_sql::Builder::default())
    .run(tauri::generate_context!())
    .expect("error while running tauri application");
}

Platform and Version

Environment
  › OS: Windows 10.0.19045 X64
  › Webview2: 108.0.1462.76
  › MSVC:
      - Visual Studio Community 2019
      - Visual Studio Build Tools 2022
      - Visual Studio Build Tools 2017
  › Node.js: 18.12.1
  › npm: 8.19.2
  › pnpm: Not installed!
  › yarn: 1.5.1
  › rustup: 1.25.1
  › rustc: 1.66.0
  › cargo: 1.66.0
  › Rust toolchain: stable-x86_64-pc-windows-msvc

Packages
  › @tauri-apps/cli [NPM]: 1.2.2
  › @tauri-apps/api [NPM]: 1.2.0
  › tauri [RUST]: 1.2.3,
  › tauri-build [RUST]: 1.2.1,
  › tao [RUST]: 0.15.8,
  › wry [RUST]: 0.23.4,

App
  › build-type: bundle
  › CSP: unset
  › distDir: ../dist
  › devPath: http://localhost:5173/
  › framework: Vue.js
  › bundler: Vite

App directory structure
  ├─ .vscode
  ├─ dist
  ├─ node_modules
  ├─ public
  ├─ src
  └─ src-tauri

Stacktrace

error[E0277]: the trait bound `tauri_plugin_sql::Builder: Plugin<tauri_runtime_wry::Wry<EventLoopMessage>>` is not satisfied
[0]     --> src\main.rs:8:13
[0]      |
[0] 8    |     .plugin(tauri_plugin_sql::Builder::default())
[0]      |      ------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait 
 Plugin<tauri_runtime_wry::Wry<EventLoopMessage>>` is not implemented for `tauri_plugin_sql::Builder`
[0]      |      |
[0]      |      required by a bound introduced by this call
[0]      |
[0] note: required by a bound in `tauri::Builder::<R>::plugin`
[0]     --> C:\Users\xxxxxxx\.cargo\registry\src\github.com-1ecc6299db9ec823\tauri-1.2.3\src\app.rs:1170:20
[0]      |
[0] 1170 |   pub fn plugin<P: Plugin<R> + 'static>(mut self, plugin: P) -> Self {
[0]      |                    ^^^^^^^^^ required by this bound in `tauri::Builder::<R>::plugin`
[0]
For more information about this error, try `rustc --explain E0277`.
error: could not compile `app` due to previous error        n)

Or is there anything I'm doing wrong? I didn't find anyone else having this issue....

chris-gassner avatar Jan 12 '23 10:01 chris-gassner

Figured it out, the documentation for the plugin is missing something. It should be:

fn main() {
  tauri::Builder::default()
    .plugin(tauri_plugin_sql::Builder::default().build())
    .run(tauri::generate_context!())
    .expect("error while running tauri application");
}

Adding the .build() call makes it work

chris-gassner avatar Jan 12 '23 10:01 chris-gassner

@chris-gassner ah!! thanks for sharing!

tdwesten avatar Jan 14 '23 21:01 tdwesten

@Zertz note though that the store plugin actually doesn't work on android right now due to tauri-apps/tauri#6054

JonasKruckenberg avatar Jan 14 '23 21:01 JonasKruckenberg

As you can see in my original post, this doesn't seem like it is the same problem as I'm using PluginBuilder::default().build().

Also, I'm not trying to nor do I want to build for Android so I'm not sure how that relates to my original issue?

Zertz avatar Jan 15 '23 17:01 Zertz

Closed by accident

FabianLars avatar Jan 15 '23 17:01 FabianLars

Also, I'm not trying to nor do I want to build for Android so I'm not sure how that relates to my original issue?

You are correct, it does not. The discussion up until got pretty sidetracked. The issue you're facing is that both your app and the plugin are depending on the tauri crate. But as one depends on [email protected] (your app) and one depends on [email protected] the compiler internally sees both Plugin traits as different. So the plugins implement the [email protected]::plugin::Plugin trait while your app expects them to implement the [email protected]::plugin::Plugin trait. This problem has been way worse in older versions of Rust and I know the language team has done work to make this less common.I might be wrong but I think there's not much we can do since this is fundamentally a language limitation.

JonasKruckenberg avatar Jan 15 '23 21:01 JonasKruckenberg

Awesome, thanks for the detailed explanation!

Zertz avatar Jan 15 '23 22:01 Zertz

All the plugins have v2 versions now so i'm closing this now :) Check out the v2 branch of the plugins repo https://github.com/tauri-apps/plugins-workspace/tree/v2

FabianLars avatar May 31 '23 19:05 FabianLars