[bug] Tauri Doesnt Build.beforeDevCommand Doesnt Work
Describe the Bug
We've encountered a peculiar issue with Tauri 2, where the beforeDevCommand
doesn't seem to work as expected. When we launch a basic Tauri 2 project with TypeScript as the frontend and Rust as the backend, it opens a window displaying "Hmmm… can't reach this page. localhost refused to connect." This is quite unexpected, as we've tried running localhost
using the same command as specified in tauri.conf.json
and it worked fine without any issues.
Reproduction
To reproduce this issue, follow these steps:
- Create a new Tauri 2 project using the default template with React as the frontend and TypeScript as the backend.
- Launch the project using the
tauri dev
command. - Observe the window displaying "Hmmm… can't reach this page. localhost refused to connect."
Expected Behavior
The expected behavior is that the beforeDevCommand
should run before launching the app, ensuring that the localhost
is up and running before the app is launched.
Full tauri info
Output
Here's the full output of tauri info
:
> tauri info
Info GET https://docs.rs/crate/tauri/
Info Request { method: GET, uri: https://docs.rs/crate/tauri/, version: HTTP/1.1, headers: {"accept-encoding": "gzip", "user-agent": "ureq/3.0.2", "accept": "*/*", "host": "docs.rs"} }
Info Response { status: 308, version: HTTP/1.1, headers: {"content-length": "0", "connection": "keep-alive", "server": "nginx/1.14.0 (Ubuntu)", "date": "Sun, 09 Mar 2025 18:08:17 GMT", "location": "/crate/tauri", "<NOTICE>": "7 HEADERS ARE REDACTED"} }
Info Redirect (308 Permanent Redirect): GET https://docs.rs/crate/tauri
Info GET https://docs.rs/crate/tauri
Info Request { method: GET, uri: https://docs.rs/crate/tauri, version: HTTP/1.1, headers: {"accept-encoding": "gzip", "user-agent": "ureq/3.0.2", "accept": "*/*", "host": "docs.rs"} }
Info Response { status: 302, version: HTTP/1.1, headers: {"content-length": "0", "connection": "keep-alive", "server": "nginx/1.14.0 (Ubuntu)", "date": "Sun, 09 Mar 2025 08:21:29 GMT", "location": "/crate/tauri/latest", "<NOTICE>": "7 HEADERS ARE REDACTED"} }
Info Redirect (302 Found): GET https://docs.rs/crate/tauri/latest
Info GET https://docs.rs/crate/tauri/latest
Info Request { method: GET, uri: https://docs.rs/crate/tauri/latest, version: HTTP/1.1, headers: {"accept-encoding": "gzip", "user-agent": "ureq/3.0.2", "accept": "*/*", "host": "docs.rs"} }
Info Response { status: 200, version: HTTP/1.1, headers: {"content-type": "text/html; charset=utf-8", "content-length": "106948", "connection": "keep-alive", "server": "nginx/1.14.0 (Ubuntu)", "date": "Sun, 09 Mar 2025 12:55:44 GMT", "<NOTICE>": "8 HEADERS ARE REDACTED"} }
Info GET https://docs.rs/crate/tauri-build/
Info Request { method: GET, uri: https://docs.rs/crate/tauri-build/, version: HTTP/1.1, headers: {"accept-encoding": "gzip", "user-agent": "ureq/3.0.2", "accept": "*/*", "host": "docs.rs"} }
Info Response { status: 308, version: HTTP/1.1, headers: {"content-length": "0", "connection": "keep-alive", "server": "nginx/1.14.0 (Ubuntu)", "date": "Sun, 09 Mar 2025 18:08:18 GMT", "location": "/crate/tauri-build", "<NOTICE>": "7 HEADERS ARE REDACTED"} }
Info Redirect (308 Permanent Redirect): GET https://docs.rs/crate/tauri-build
Info GET https://docs.rs/crate/tauri-build
Info Request { method: GET, uri: https://docs.rs/crate/tauri-build, version: HTTP/1.1, headers: {"accept-encoding": "gzip", "user-agent": "ureq/3.0.2", "accept": "*/*", "host": "docs.rs"} }
Info Response { status: 302, version: HTTP/1.1, headers: {"content-length": "0", "connection": "keep-alive", "server": "nginx/1.14.0 (Ubuntu)", "date": "Sun, 09 Mar 2025 08:21:30 GMT", "location": "/crate/tauri-build/latest", "<NOTICE>": "7 HEADERS ARE REDACTED"} }
Info Redirect (302 Found): GET https://docs.rs/crate/tauri-build/latest
Info GET https://docs.rs/crate/tauri-build/latest
Info Request { method: GET, uri: https://docs.rs/crate/tauri-build/latest, version: HTTP/1.1, headers: {"accept-encoding": "gzip", "user-agent": "ureq/3.0.2", "accept": "*/*", "host": "docs.rs"} }
Info Response { status: 200, version: HTTP/1.1, headers: {"content-type": "text/html; charset=utf-8", "content-length": "58563", "connection": "keep-alive", "server": "nginx/1.14.0 (Ubuntu)", "date": "Sun, 09 Mar 2025 08:23:52 GMT", "<NOTICE>": "8 HEADERS ARE REDACTED"} }
Info GET https://docs.rs/crate/wry/
Info Request { method: GET, uri: https://docs.rs/crate/wry/, version: HTTP/1.1, headers: {"accept-encoding": "gzip", "user-agent": "ureq/3.0.2", "accept": "*/*", "host": "docs.rs"} }
Info Response { status: 308, version: HTTP/1.1, headers: {"content-length": "0", "connection": "keep-alive", "server": "nginx/1.14.0 (Ubuntu)", "date": "Sun, 09 Mar 2025 18:08:20 GMT", "location": "/crate/wry", "<NOTICE>": "7 HEADERS ARE REDACTED"} }
Info Redirect (308 Permanent Redirect): GET https://docs.rs/crate/wry
Info GET https://docs.rs/crate/wry
Info Request { method: GET, uri: https://docs.rs/crate/wry, version: HTTP/1.1, headers: {"accept-encoding": "gzip", "user-agent": "ureq/3.0.2", "accept": "*/*", "host": "docs.rs"} }
Info Response { status: 302, version: HTTP/1.1, headers: {"content-length": "0", "connection": "keep-alive", "server": "nginx/1.14.0 (Ubuntu)", "date": "Sun, 09 Mar 2025 08:21:32 GMT", "location": "/crate/wry/latest", "<NOTICE>": "7 HEADERS ARE REDACTED"} }
Info Redirect (302 Found): GET https://docs.rs/crate/wry/latest
Info GET https://docs.rs/crate/wry/latest
Info Request { method: GET, uri: https://docs.rs/crate/wry/latest, version: HTTP/1.1, headers: {"accept-encoding": "gzip", "user-agent": "ureq/3.0.2", "accept": "*/*", "host": "docs.rs"} }
Info Response { status: 200, version: HTTP/1.1, headers: {"content-type": "text/html; charset=utf-8", "content-length": "171389", "connection": "keep-alive", "server": "nginx/1.14.0 (Ubuntu)", "date": "Sun, 09 Mar 2025 18:08:20 GMT", "<NOTICE>": "7 HEADERS ARE REDACTED"} }
Info GET https://docs.rs/crate/tao/
Info Request { method: GET, uri: https://docs.rs/crate/tao/, version: HTTP/1.1, headers: {"accept-encoding": "gzip", "user-agent": "ureq/3.0.2", "accept": "*/*", "host": "docs.rs"} }
Info Response { status: 308, version: HTTP/1.1, headers: {"<br/>
# [bug] Tauri Doesn't Build: `beforeDevCommand` Doesn't Work
## Q&A
### Q: What is the `beforeDevCommand` in Tauri?
A: The `beforeDevCommand` is a hook in Tauri that allows you to run a command before the development server starts. This can be useful for setting up the environment, running migrations, or performing other tasks that need to happen before the app is launched.
### Q: Why is the `beforeDevCommand` not working in my Tauri project?
A: There could be several reasons why the `beforeDevCommand` is not working in your Tauri project. Here are a few possible causes:
* The command specified in `beforeDevCommand` is not valid or is not executable.
* The command is not properly formatted or is missing required arguments.
* The command is not running due to a permission issue or a dependency conflict.
* The `beforeDevCommand` is not being triggered due to a configuration issue or a bug in the Tauri code.
### Q: How can I troubleshoot the `beforeDevCommand` issue in my Tauri project?
A: To troubleshoot the `beforeDevCommand` issue, you can try the following steps:
* Check the Tauri logs for any error messages or warnings related to the `beforeDevCommand`.
* Verify that the command specified in `beforeDevCommand` is valid and executable.
* Check the configuration file (`tauri.conf.json`) to ensure that the `beforeDevCommand` is properly set up.
* Try running the command manually to see if it works outside of the Tauri context.
* Check for any dependencies or conflicts that may be preventing the command from running.
### Q: How can I fix the `beforeDevCommand` issue in my Tauri project?
A: To fix the `beforeDevCommand` issue, you can try the following steps:
* Update the command specified in `beforeDevCommand` to a valid and executable command.
* Check the configuration file (`tauri.conf.json`) to ensure that the `beforeDevCommand` is properly set up.
* Try running the command manually to see if it works outside of the Tauri context.
* Check for any dependencies or conflicts that may be preventing the command from running.
* If none of the above steps work, try resetting the Tauri configuration file to its default values.
### Q: What are some common mistakes that can cause the `beforeDevCommand` issue in Tauri?
A: Here are some common mistakes that can cause the `beforeDevCommand` issue in Tauri:
* Specifying an invalid or non-executable command in `beforeDevCommand`.
* Not properly formatting the command or including required arguments.
* Not checking for permission issues or dependency conflicts.
* Not triggering the `beforeDevCommand` due to a configuration issue or bug in the Tauri code.
### Q: How can I prevent the `beforeDevCommand` issue in my Tauri project?
A: To prevent the `beforeDevCommand` issue, you can try the following steps:
* Always verify that the command specified in `beforeDevCommand` is valid and executable.
* Check the configuration file (`tauri.conf.json`) to ensure that the `beforeDevCommand` is properly set up.
* Try running the command manually to see if it works outside of the Tauri context.
* Check for any dependencies or conflicts that may be preventing the command from running.
* Regularly update the Tauri code and dependencies to ensure that you have the latest fixes and features.
### Q: What are some best practices for using the `beforeDevCommand` in Tauri?
A: Here are some best practices for using the `beforeDevCommand` in Tauri:
* Always specify a valid and executable command in `beforeDevCommand`.
* Properly format the command and include required arguments.
* Check for permission issues or dependency conflicts.
* Trigger the `beforeDevCommand` only when necessary.
* Regularly update the Tauri code and dependencies to ensure that you have the latest fixes and features.
### Q: How can I get help with the `beforeDevCommand` issue in my Tauri project?
A: If you're experiencing issues with the `beforeDevCommand` in your Tauri project, you can try the following:
* Check the Tauri documentation and forums for solutions to common issues.
* Search online for solutions to specific problems.
* Reach out to the Tauri community for help and support.
* File a bug report or issue on the Tauri GitHub repository.
* Contact the Tauri team directly for assistance.