Replies: 1 comment
-
does is your project in a workspace? if so, did you try one outside of it as a sanity check? p.s. since this is unrelated to tauri, you'll probably have better luck asking in the vite community if not done already. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone,
I've been trying to get my existing Vanilla JS application (HTML, CSS, JS) to work with Tauri v2 and Vite, but I'm stuck on a persistent issue: The Vite development server returns a 404 error for my index.html when I access the Vite URL directly in the browser. Consequently, the Tauri window remains blank in development mode (npm run tauri dev).
System Environment:
Problem Description:
When I run npm run tauri dev, the terminal output shows Vite starting (e.g., on http://localhost:5173/). The Rust part also compiles successfully, and the Tauri application ("visu") launches. However:
This happens even with an absolutely minimal index.html, style.css, and script.js (without any Tauri-specific imports or code), when Vite is configured to use the src folder as its root.
Minimal Configuration Reproducing the Error:
Visualisierung/app/Visu/
├── node_modules/
├── src/
│ ├── index.html
│ ├── script.js
│ └── style.css
├── src-tauri/
│ ├── capabilities/
│ │ └── (empty for this test, or a minimal default.json)
│ ├── icons/
│ ├── src/
│ │ └── main.rs (standard from create-tauri-app)
│ ├── build.rs (standard: tauri_build::build())
│ ├── Cargo.toml
│ └── tauri.conf.json
├── vite.config.js
├── package.json
└── package-lock.json
JavaScript
import { defineConfig } from 'vite';
export default defineConfig({
root: 'src',
server: {
port: 5173, // or any other free port
strictPort: true
},
build: {
outDir: '../dist', // Relative to root
emptyOutDir: true
}
});
(Based on and our latest attempts)
HTML
Hello from Vite!
<script type="module" src="/script.js"></script>JavaScript
console.log("Minimal script.js loaded");
// No Tauri imports for this pure Vite test
JSON
{
"$schema": "https://schema.tauri.app/config/2",
"productName": "visu",
"version": "0.1.0",
"identifier": "com.visu.app",
"build": {
"devUrl": "http://localhost:5173", // Must match Vite port
"frontendDist": "../dist",
"beforeDevCommand": "npm run dev",
"beforeBuildCommand": "npm run build"
},
"app": {
"withGlobalTauri": false,
"windows": [
{
"label": "main",
"title": "visu",
"width": 1200,
"height": 800
}
],
"security": {
"csp": null
// No "capabilities" for this test to isolate the issue
}
},
"bundle": { /* ... standard ... */ }
}
(Based on and our latest adjustments)
JSON
{
"name": "visu",
"private": true,
"version": "0.1.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"tauri": "tauri"
},
"devDependencies": {
"@tauri-apps/cli": "^2.5.0", // or your exact ^2 version
"vite": "^5.2.10" // or your exact v5/v6 version
},
"dependencies": {
"@tauri-apps/api": "^2.5.0" // Even if not used in minimal JS, it's in the project
}
}
(Based on and our Vite additions)
What I've already tried (without success for the Vite 404 error):
The strange part is that Vite reports in the terminal that it's "ready" and listening on the port, but then serves a 404 for index.html (and any other file in the src folder) when the URL is accessed in the browser.
Does anyone have an idea what could be the issue with Vite on macOS here, or what else I could check to get Vite to serve the index.html from the src directory correctly? As long as this isn't working, Tauri cannot load the frontend.
Thanks in advance for any help!
Beta Was this translation helpful? Give feedback.
All reactions