Closed probablykasper closed 2 years ago
what is the advantage of this? seems like creating an empty directory is better and easier rather than implementing this solution.
Pretty much every user will run into this error when creating a Tauri project, and when creating an action that runs cargo check
, then they'll have to figure out why it's happening and learn the workaround. It's a confusing/annoying error because your code works perfectly, but you're still getting a linting/checking error.
I'd love to not see the error anymore, and avoid the extra stuff required to deal with it in actions even though it's not much.
The way I see this, is that cargo check
should fail if the distDir
doesn't exist and new tauri projects or new tauri users should be aware of that, because if distDir
doesn't exist then your workflow is faulty and probably missed a step to build your front-end but if you don't want to build your front-end then just create an empty dir. It is far less work than you expect and better than implementing an env var.
I agree with Amr here, the distDir
is part of the application so it would be weird to handle things this way. We can't get back to using env vars, it's too annoying for Rust developers.
@amrbashir @lucasfernog To be clear tauri build
would still panic if distDir
doesn't exist. Is it actually common enough to run cargo build
directly for the final build?
Yeah pure Rust users (wasm etc) just go with cargo run
instead of tauri dev
.
I agree with Amr here, the
distDir
is part of the application so it would be weird to handle things this way.
It's also weird to run an apparently innocuous command such as cargo clippy
on CI and have it fail because a directory that is not supposed to be checked in to the tree is indeed not checked in. And the available workarounds are not better:
dist/.gitkeep
to ensure that dist
exists, but then that empty file will be part of the application embedded assets and there's no way to prevent that.distDir
before running any Cargo command that may build the application, but that means that someone will have to externally reinvent the wheel of parsing that file.dist
directory, when cargo clippy
doesn't need it at all?mkdir dist
on a CI workflow beforehand, but then the workflow has to be changed if the distDir
configuration value changes, which is inelegant.I'm not familiar enough with the Tauri build lifecycle to know what would be the best course of action here, but I think that the current behavior is far from ideal, because it makes perfectly valid and fine workflows clunkier for no good reason.
Isn't it possible to delay that existence check until an attempt to actually embed the assets is made? That sounds like a better idea to me, although I don't know how feasible it is.
@AlexTMjugador I'll add: It's weird when new users get an error after following the Getting Started page (SvelteKit). Please re-open.
It shouldn't be as common anymore since we removed the default features from the templates here: https://github.com/tauri-apps/tauri/pull/6074 (not yet released).
Effectively this means that tauri is in dev mode by default, therefore it looks at the devPath instead of distDir.
@FabianLars I see, so, terribly simplified i assume, the problem is that IntelliJ runs Cargo checks without tauri, ofc, and Cargo alone doesn't know what tauri will do?
I would not call this terribly simplified. It's pretty much exactly what's happening. To expand a bit on what's happening, tauri's cli will invoke cargo like so:
tauri dev
-> cargo build --no-default-features
(devPath)
tauri build
-> cargo build --features custom-protocol
(distDir)
intellij, rust-analyzer, cargo check in cli all by default do just cargo build/check
without saying anything about the features.
And because before 6074, custom-protocol was a default feature, and therefore always enabled unless explicitly disabled, the IDEs threw errors because they basically did the equivalent of tauri build
without building your frontend first (commonly set as beforeBuildCommand in tauri.conf which also only get's executed by tauri's cli, not cargo itself)
I'm still getting the error. My config is:
"devPath": "http://localhost:1420/",
"distDir": "../dist",
and it looks the distDir
which is a panic error. Do I need to tell every user to create ../dist
everytime they try running my app? I only run tauri dev
can I also run cargo run
inside the src-tauri?
@Rizary Remove this line (and this line only!): https://github.com/ARK-Builders/ARK-Shelf-Desktop/blob/8cde8defefe804384fcfd6eaa714d4faa4067a35/src-tauri/Cargo.toml#L29 - this should prevent the error.
can I also run cargo run inside the src-tauri?
Yes. But then you have to run the beforeDevCommand yourself)
@FabianLars Does removing that line prevent using custom protocols? I'm new to Tauri so I'm still working out the details, but it does seem odd that when running in dev mode, we get an error if the production build dir isn't present?
No it doesn't. The name is quite misleading nowadays but it simply tells Tauri whether it should serve devPath or distDir - distDir uses a custom protocol (since before generic custom protocols were really a thing), and devPath doesn't (it still does if you disable the dev server for added confusion) hence the name.
@Rizary Remove this line (and this line only!): https://github.com/ARK-Builders/ARK-Shelf-Desktop/blob/8cde8defefe804384fcfd6eaa714d4faa4067a35/src-tauri/Cargo.toml#L29 - this should prevent the error.
can I also run cargo run inside the src-tauri?
Yes. But then you have to run the beforeDevCommand yourself)
I still get the:
proc macro panicked message: The
distDir
configuration is set to"../dist"
but this path doesn't exist
But I think it's due to my editor I guess? So basically nowadays we don't need that custom-protocol right? I think I don't have any custom protocol in the project.
You don't need the default
feature for it, no. You must keep the feature itself though if you ever want to build your app via the tauri build
command.
And yes, if your ide is configured to enable all features then you'll still see this issue.
Describe the problem
If you have a
build
folder that doesn't exist, you expect this error from your linter as well as when runningcargo check
in a GitHub action:Describe the solution you'd like
If
distDir
doesn't exist, treat it like as an empty directory, but only if an environment variable likeTAURI_STRICT_PATHS
is not true. Whentauri build
runs, it should enableTAURI_STRICT_PATHS
.The disadvantage is that running
cargo build
directly will not panic ifdistDir
doesn't exist.