DEV Community

Sekti Wicaksono
Sekti Wicaksono

Posted on

Tanstack Router + Vite race condition in filewatcher (EPERM)

Recently I got an issue when creating a new route using Tanstack Router + Vite

So by adding this config could solved the issue of EPERM: operation not permitted like below:

Error: EPERM: operation not permitted, rename 'D:\IMT\imt-fe\.tanstack\tmp\884d3334-4715af826dad72bfa663dbba03a36060' -> 'D:\IMT\imt-fe\src\routes\users\$phone_number\edit.tsx'
>     at file:///D:/IMT/imt-fe/node_modules/@tanstack/router-generator/dist/esm/generator.js:143:13
>     at async generate (file:///D:/IMT/imt-fe/node_modules/@tanstack/router-plugin/dist/esm/core/router-generator-plugin.js:39:4)
>     at async PluginContext.watchChange (file:///D:/IMT/imt-fe/node_modules/@tanstack/router-plugin/dist/esm/core/router-generator-plugin.js:49:4)
>     at async Promise.all (index 1)
>     at async EnvironmentPluginContainer.hookParallel (file:///D:/IMT/imt-fe/node_modules/vite/dist/node/chunks/node.js:29604:3)
>     at async EnvironmentPluginContainer.watchChange (file:///D:/IMT/imt-fe/node_modules/vite/dist/node/chunks/node.js:29771:3)
>     at async Promise.all (index 0)
>     at async onFileAddUnlink (file:///D:/IMT/imt-fe/node_modules/vite/dist/node/chunks/node.js:25530:3)
Enter fullscreen mode Exit fullscreen mode

By adding usePolling and stabilityThreshold props into vite.config.ts, the route creation happen like magic during development process (a bit slow but your server won't shut)

vite.config.ts

const config = defineConfig({
  .... your other config ....
  // solves EPERM 
  server: {
    watch: {
      usePolling: true,
      interval: 300,
      awaitWriteFinish: {
        stabilityThreshold: 500,
        pollInterval: 100,
      },
    }
  }
})
Enter fullscreen mode Exit fullscreen mode

Note: This config doesn't depend on specific OS/hardware settings. If you still encounter similar issues when generating multiple routes at once, simply increase the stabilityThreshold interval slightly (e.g., 500 → 800) as a further adjustment.

Top comments (0)