tauri-apps / tauri

Build smaller, faster, and more secure desktop applications with a web frontend.
https://tauri.app
Apache License 2.0
81.76k stars 2.45k forks source link

[bug] npm migrate can't migrate plugins pulled from `v1` branch #10650

Closed gknapp closed 3 weeks ago

gknapp commented 4 weeks ago

Describe the bug

Following the commands on the RC blog post, I ran npm run tauri migrate after installing @tauri-apps/cli@next.

NPM deps were upgraded to ^2.0.0-rc.0 including @tauri-apps/plugins-*

Encountered the error:

the package webkit2gtk-sys links to the native library web_kit2, but it conflicts with a previous package which links to web_kit2 as well: package webkit2gtk-sys v2.0.1

Reproduction

From a 1.6.0 app using the following cargo deps:

tauri = { version = "2.0.0-rc", features = [] }
tauri-plugin-dialog = "2.0.0-rc.0"
tauri-plugin-shell = "2.0.0-rc.0"
tauri-plugin-store = { branch = "v1", git = "https://github.com/tauri-apps/plugins-workspace" }
tauri-plugin-window-state = { branch = "v1", git = "https://github.com/tauri-apps/plugins-workspace" }
npm install @tauri-apps/cli@next
npm run tauri migrate

Expected behavior

migrate without encountering errors. Full error encountered:

> set RUST_BACKTRACE=full& tauri migrate

    Info Installing NPM dependencies "@tauri-apps/api@^2.0.0-rc.0", "@tauri-apps/plugin-dialog", "@tauri-apps/plugin-shell"...

added 2 packages, changed 1 package, and audited 350 packages in 5s

118 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
    Info Installing Cargo dependencies "tauri-plugin-dialog", "tauri-plugin-shell"...
    Updating crates.io index
      Adding tauri-plugin-dialog v2.0.0-rc.0 to dependencies
      Adding tauri-plugin-shell v2.0.0-rc.0 to dependencies
    Updating crates.io index
error: failed to select a version for `webkit2gtk-sys`.
    ... required by package `wry v0.18.3`
    ... required by package `wry v0.18.3`
    ... which satisfies dependency `wry = "^0.18.3"` of package `tauri-runtime-wry v0.9.0`
    ... which satisfies dependency `tauri-runtime-wry = "^0.9.0"` of package `tauri v1.0.0`
    ... which satisfies dependency `tauri = "^1"` of package `tauri-plugin-store v0.0.0 (https://github.com/tauri-apps/plugins-workspace?branch=v1#5e3900e6)`
    ... which satisfies git dependency `tauri-plugin-store` (locked to 0.0.0) of package `app v1.0.0 (C:\Apps91\Mapestry\src-tauri)`
versions that meet the requirements `^0.18` are: 0.18.0

the package `webkit2gtk-sys` links to the native library `web_kit2`, but it conflicts with a previous package which links to `web_kit2` as well:
package `webkit2gtk-sys v2.0.1`
    ... which satisfies dependency `ffi = "^2.0.1"` of package `webkit2gtk v2.0.1`
    ... which satisfies dependency `webkit2gtk = "=2.0.1"` of package `tauri v2.0.0-rc.0`
    ... which satisfies dependency `tauri = "^2.0.0-rc"` of package `app v1.0.0 (C:\Apps91\Mapestry\src-tauri)`
Only one package in the dependency graph may specify the same links value. This helps ensure that only one copy of a native library is linked in the final binary. Try to adjust your dependencies so that only one package uses the `links = "web_kit2"` value. For more information, see https://doc.rust-lang.org/cargo/reference/resolver.html#links.

failed to select a version for `webkit2gtk-sys` which could resolve this conflict
    Error failed to migrate from v1: Error installing new Cargo packages: Failed to install Cargo dependencies

Full tauri info output

$ npm run tauri info

[✔] Environment
    - OS: Windows 10.0.22631 X64
    ✔ WebView2: 127.0.2651.105
    ✔ MSVC: Visual Studio Build Tools 2022
    ✔ rustc: 1.78.0 (9b00956e5 2024-04-29)
    ✔ cargo: 1.78.0 (54d8815d0 2024-03-26)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-x86_64-pc-windows-msvc (default)
    - node: 20.10.0
    - npm: 10.2.3

[-] Packages
    - tauri [RUST]: 1.6.1
    - tauri-build [RUST]: 1.5.1
    - wry [RUST]: 0.24.7
    - tao [RUST]: 0.16.8
    - @tauri-apps/api [NPM]: 2.0.0-rc.0
    - @tauri-apps/cli [NPM]: 2.0.0-rc.3

[-] App
    - build-type: bundle
    - CSP: default-src 'self' data: blob:; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; connect-src ipc: http://ipc.localhost
    - frontendDist: ../dist
    - devUrl: http://localhost:3055/
    - framework: React
    - bundler: Rollup

Stack trace

Updating crates.io index
error: failed to select a version for `webkit2gtk-sys`.
    ... required by package `wry v0.18.3`
    ... required by package `wry v0.18.3`
    ... which satisfies dependency `wry = "^0.18.3"` of package `tauri-runtime-wry v0.9.0`
    ... which satisfies dependency `tauri-runtime-wry = "^0.9.0"` of package `tauri v1.0.0`
    ... which satisfies dependency `tauri = "^1"` of package `tauri-plugin-store v0.0.0 (https://github.com/tauri-apps/plugins-workspace?branch=v1#5e3900e6)`
    ... which satisfies git dependency `tauri-plugin-store` (locked to 0.0.0) of package `app v1.0.0 (C:\Apps91\Mapestry\src-tauri)`
versions that meet the requirements `^0.18` are: 0.18.0

the package `webkit2gtk-sys` links to the native library `web_kit2`, but it conflicts with a previous package which links to `web_kit2` as well:
package `webkit2gtk-sys v2.0.1`
    ... which satisfies dependency `ffi = "^2.0.1"` of package `webkit2gtk v2.0.1`
    ... which satisfies dependency `webkit2gtk = "=2.0.1"` of package `tauri v2.0.0-rc.0`
    ... which satisfies dependency `tauri = "^2.0.0-rc"` of package `app v1.0.0 (C:\Apps91\Mapestry\src-tauri)`
Only one package in the dependency graph may specify the same links value. This helps ensure that only one copy of a native library is linked in the final binary. Try to adjust your dependencies so that only one package uses the `links = "web_kit2"` value. For more information, see https://doc.rust-lang.org/cargo/reference/resolver.html#links.

failed to select a version for `webkit2gtk-sys` which could resolve this conflict
    Error failed to migrate from v1: Error installing new Cargo packages: Failed to install Cargo dependencies

Additional context

Ran npm commands from gitbash terminal.

FabianLars commented 4 weeks ago

Change the store and window-state plugin to use the v2 branch. I think the migrate command currently can't handle git dependencies, which i guess it should considering that v1 plugins never got released...

gknapp commented 4 weeks ago

Change the store and window-state plugin to use the v2 branch. I think the migrate command currently can't handle git dependencies, which i guess it should considering that v1 plugins never got released...

I figured this might need changing - once updated, do I re-run migrate or another command?

Updated deps to:

tauri-plugin-store = { branch = "v2", git = "https://github.com/tauri-apps/plugins-workspace" }
tauri-plugin-window-state = { branch = "v2", git = "https://github.com/tauri-apps/plugins-workspace" }
FabianLars commented 4 weeks ago

once updated, do I re-run migrate or another command?

Hmm, probably re-run it. I'm not sure how well the migrate command handles failures like this right now so maybeee you have to reset the project to v1 again (assuming you have version control set up), change the plugins deps and run it again 🤔

gknapp commented 4 weeks ago

I've re-organised main.rs and lib.rs per the migration docs. Looks like the migration worked through my tauri.conf.json and extracted the allowlist perms into capabilities/migrated.json.

I'm just updating shell plugin code. I'll raise a separate issue if I run into trouble there. I'll leave this open until I get a running app stood up. Thanks for the help.

gknapp commented 4 weeks ago

It appears the migration script did duplicate a permission from my v1 allow list:

  "permissions": [
    "core:default",
    {
      "identifier": "fs:scope",
      "allow": [
        "$APP/*",
        "$DESKTOP/*",
        "$RESOURCE/*"
      ]
    },
    "core:window:allow-set-title",
    "shell:allow-execute",
    "shell:allow-open",
    "shell:allow-open", // dupe
    "dialog:allow-open",
    "dialog:allow-save",
    {
      "identifier": "http:default",
      "allow": [{ "url": "file:///" }]
    }
  ]
gknapp commented 3 weeks ago

During npm start I'm seeing:

Permission fs:scope not found, expected one of core:app:default, ...

It's as if it can't see the fs:scope object in capabilities/migrated.json

   Compiling tauri-plugin-shell v2.0.0-rc.0
error: failed to run custom build command for `app v1.0.0 (C:\yyy\src-tauri)`

Caused by:
  process didn't exit successfully: `C:\yyy\src-tauri\target\debug\build\app-d15e51f6b2c8c9a8\build-script-build` (exit code: 1)
  --- stdout
  cargo:rerun-if-env-changed=TAURI_CONFIG
  cargo:rerun-if-changed=tauri.conf.json
  cargo:rustc-check-cfg=cfg(desktop)
  cargo:rustc-cfg=desktop
  cargo:rustc-check-cfg=cfg(mobile)
  cargo:rustc-env=TAURI_ANDROID_PACKAGE_NAME_APP_NAME=yyy
  cargo:rustc-env=TAURI_ANDROID_PACKAGE_NAME_PREFIX=yyy
  cargo:rustc-check-cfg=cfg(dev)
  cargo:rustc-cfg=dev
  cargo:PERMISSION_FILES_PATH=C:\yyy\src-tauri\target\debug\build\app-9ea48d623f55e621\out\app-manifest\__app__-permission-files
  cargo:rerun-if-changed=capabilities
  Permission fs:scope not found, expected one of core:app:default,

The V2 docs state the variables I've used (see previous post) are still valid in V2.

lucasfernog commented 3 weeks ago

During npm start I'm seeing:

Permission fs:scope not found, expected one of core:app:default, ...

It's as if it can't see the fs:scope object in capabilities/migrated.json

   Compiling tauri-plugin-shell v2.0.0-rc.0
error: failed to run custom build command for `app v1.0.0 (C:\yyy\src-tauri)`

Caused by:
  process didn't exit successfully: `C:\yyy\src-tauri\target\debug\build\app-d15e51f6b2c8c9a8\build-script-build` (exit code: 1)
  --- stdout
  cargo:rerun-if-env-changed=TAURI_CONFIG
  cargo:rerun-if-changed=tauri.conf.json
  cargo:rustc-check-cfg=cfg(desktop)
  cargo:rustc-cfg=desktop
  cargo:rustc-check-cfg=cfg(mobile)
  cargo:rustc-env=TAURI_ANDROID_PACKAGE_NAME_APP_NAME=yyy
  cargo:rustc-env=TAURI_ANDROID_PACKAGE_NAME_PREFIX=yyy
  cargo:rustc-check-cfg=cfg(dev)
  cargo:rustc-cfg=dev
  cargo:PERMISSION_FILES_PATH=C:\yyy\src-tauri\target\debug\build\app-9ea48d623f55e621\out\app-manifest\__app__-permission-files
  cargo:rerun-if-changed=capabilities
  Permission fs:scope not found, expected one of core:app:default,

The V2 docs state the variables I've used (see previous post) are still valid in V2.

I think the migration added the FS scope but not the FS plugin. I'll run through the list of changes needed here today.

lucasfernog commented 3 weeks ago

During npm start I'm seeing: Permission fs:scope not found, expected one of core:app:default, ... It's as if it can't see the fs:scope object in capabilities/migrated.json

   Compiling tauri-plugin-shell v2.0.0-rc.0
error: failed to run custom build command for `app v1.0.0 (C:\yyy\src-tauri)`

Caused by:
  process didn't exit successfully: `C:\yyy\src-tauri\target\debug\build\app-d15e51f6b2c8c9a8\build-script-build` (exit code: 1)
  --- stdout
  cargo:rerun-if-env-changed=TAURI_CONFIG
  cargo:rerun-if-changed=tauri.conf.json
  cargo:rustc-check-cfg=cfg(desktop)
  cargo:rustc-cfg=desktop
  cargo:rustc-check-cfg=cfg(mobile)
  cargo:rustc-env=TAURI_ANDROID_PACKAGE_NAME_APP_NAME=yyy
  cargo:rustc-env=TAURI_ANDROID_PACKAGE_NAME_PREFIX=yyy
  cargo:rustc-check-cfg=cfg(dev)
  cargo:rustc-cfg=dev
  cargo:PERMISSION_FILES_PATH=C:\yyy\src-tauri\target\debug\build\app-9ea48d623f55e621\out\app-manifest\__app__-permission-files
  cargo:rerun-if-changed=capabilities
  Permission fs:scope not found, expected one of core:app:default,

The V2 docs state the variables I've used (see previous post) are still valid in V2.

I think the migration added the FS scope but not the FS plugin. I'll run through the list of changes needed here today.

from my test it does add the FS plugin, maybe it's because yours failed?

gknapp commented 3 weeks ago

Update: Cut a new test branch from my v1 branch and ran RC4, can see it's completed and installed tauri-plugin-fs = "2.0.0-rc.0" and others to my Cargo.toml deps.

My migration did fail, how do I add the FS plugin - add it to my Cargo.toml dependencies?

My current deps:

[dependencies]
base64 = "0.22.0"
minifier = "0.3.0"
minify-html = "0.15.0"
scraper = "0.19.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tauri = { version = "2.0.0-rc", features = [] }
tauri-plugin-dialog = "2.0.0-rc.0"
tauri-plugin-shell = "2.0.0-rc.0"
tauri-plugin-store = { branch = "v2", git = "https://github.com/tauri-apps/plugins-workspace" }
tauri-plugin-window-state = { branch = "v2", git = "https://github.com/tauri-apps/plugins-workspace" }
thiserror = "1.0"

npm run tauri migrate exits with no output, whatever it's checking, I presume it sees my project as migrated and takes no action.

I've moved my v1 main.rs -> lib.rs and recreated main.rs per the migration guide.

gknapp commented 3 weeks ago

Should the migration script add the src-tauri/gen directory to .gitignore if the ignore file exists?

FabianLars commented 3 weeks ago

No, currently the suggestion is to commit the gen folder too. without gen/schemas though (which is what the default gitignore file does).