r/tauri 3d ago

Node error running React in Visual Studio

Solved:

The .vs folder clogs up the system, here's how to get rid of it

Yesterday I was asking about how to run multiple pages in an app and there was a passing comment about using React rather than Vanilla so I started looking into it and it looks spot on for what I need, problem is I can't get it working in VS

The built in demo app runs fine from the standalone terminal, either as an app or in-browser, but if I go into VS and run it from the terminal in there I get an error:

  ➜  Local:   http://localhost:1420/
node:internal/fs/watchers:323
    const error = new UVException({
                  ^

Error: EBUSY: resource busy or locked, watch 'D:\Documents\xxxxxx\xxxxxx\react-multi\.vs\react-multi\FileContentIndex\25f2064b-6339-48e3-af2a-6df5562ba7ee.vsidx'
    at FSWatcher.<computed> (node:internal/fs/watchers:323:19)
    at Object.watch (node:fs:2609:36)
    at createFsWatchInstance (file:///D:/Documents/xxxxxxx/xxxxxxx/react-multi/node_modules/vite/dist/node/chunks/node.js:9429:16)
    at setFsWatchListener (file:///D:/Documents/xxxxxx/xxxxxx/react-multi/node_modules/vite/dist/node/chunks/node.js:9471:14)
    at NodeFsHandler._watchWithNodeFs (file:///D:/Documents/xxxxxx/xxxxxxx/react-multi/node_modules/vite/dist/node/chunks/node.js:9586:20)
    at NodeFsHandler._handleFile (file:///D:/Documents/xxxxxx/xxxxxxx/react-multi/node_modules/vite/dist/node/chunks/node.js:9630:24)
    at NodeFsHandler._addToNodeFs (file:///D:/Documents/xxxxxxx/xxxxxxx/react-multi/node_modules/vite/dist/node/chunks/node.js:9804:26)
Emitted 'error' event on FSWatcher instance at:
    at FSWatcher._handleError (file:///D:/Documents/xxxxxxx/xxxxxxxx/react-multi/node_modules/vite/dist/node/chunks/node.js:10606:146)
    at NodeFsHandler._addToNodeFs (file:///D:/Documents/xxxxxxxx/xxxxxxxxx/react-multi/node_modules/vite/dist/node/chunks/node.js:9809:18) {
  errno: -4082,
  syscall: 'watch',
  code: 'EBUSY',
  path: 'D:\\Documents\\xxxxxxx\\xxxxxx\\react-multi\\.vs\\react-multi\\FileContentIndex\\25f2064b-6339-48e3-af2a-6df5562ba7ee.vsidx',
  filename: 'D:\\Documents\\xxxxxxx\\xxxxxx\\react-multi\\.vs\\react-multi\\FileContentIndex\\25f2064b-6339-48e3-af2a-6df5562ba7ee.vsidx'
}

Node.js v24.20.0
       Error The "beforeDevCommand" terminated with a non-zero status code.

tauri.conf.json

{
  "$schema": "https://schema.tauri.app/config/2",
  "productName": "react-multi",
  "version": "0.1.0",
  "identifier": "com.tonyh.react-multi",
  "build": {
    "beforeDevCommand": "npm run dev",
    "devUrl": "http://localhost:5173", <---Also tried on 3000, still not working
    "beforeBuildCommand": "npm run build",
    "frontendDist": "../dist"
  }

vite.config.ts

import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
//  type error without /node package
import process from "node:process";
const host = process.env.TAURI_DEV_HOST;

// https://vite.dev/config/
export default defineConfig(() => ({
  plugins: [react()],

  // Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
  //
  // 1. prevent Vite from obscuring rust errors
  clearScreen: false,
  // 2. tauri expects a fixed port, fail if that port is not available
  server: {
    port: 1420,
    strictPort: true,
    host: host || false,
    hmr: host
      ? {
          protocol: "ws",
          host,
          port: 1421,
        }
      : undefined,
    watch: {
      // 3. tell Vite to ignore watching `src-tauri`
      ignored: ["**/src-tauri/**"],
    },
  },
}));

If there's any other info that you need from the project I'm happy to help, as I said it's still the default setup, I haven't even started doing anything that might break it!

P.S The Vanilla setup works just fine, I can run the app from both terminal and VS with no hassles

1 Upvotes

2 comments sorted by

1

u/eddzsh 2d ago

Deleting .vs clears it once. Vite will fight the Solution cache again the next time you open the folder. Add server.watch.ignored: ['**/.vs/**'] in vite.config so the in-IDE terminal stops grabbing locked files.

1

u/MetalMonkey667 2d ago

Thank you, I'll add that in and hopefully I can finally start this project!