ai-toolkit icon indicating copy to clipboard operation
ai-toolkit copied to clipboard

Job deletion fails with TypeError: The property 'options.recursive' is no longer supported (fs.rmdirSync incompatibility with modern Node.js)

Open camoody1 opened this issue 1 week ago • 1 comments

This is for bugs only

Did you already ask in the discord?

Yes/No

You verified that this is a bug and not a feature request or question by asking in the discord?

Yes/No

Describe the bug

When attempting to delete a stopped (or completed) job from the Training Queue in the UI, the operation fails with the following error in the server log:

[UI] ⨯ TypeError: The property 'options.recursive' is no longer supported. Received true
[UI]     at j (F:\AI Toolkit\AI-Toolkit\ui.next\server\app\api\jobs[jobID]\delete\route.js:1:1341) {
[UI]     code: 'ERR_INVALID_ARG_VALUE'
[UI] }

This prevents cleaning up old jobs from the queue, even though manual deletion of the output folder works as a workaround.

Cause The issue is in `ui/src/app/api/jobs/[jobID]/delete/route.ts:

if (fs.existsSync(trainingFolder)) {
  fs.rmdirSync(trainingFolder, { recursive: true });
}

fs.rmdirSync() with { recursive: true } was deprecated in Node.js v14 and fully removed/enforced as an error in later versions (common in Node.js 20+ or recent LTS like 22). Many users (especially on Windows with recent Node installs) run into this because the toolkit's UI (Next.js) relies on Node.js 18+.

As of today (December 21, 2025), the main branch still uses fs.rmdirSync here: https://github.com/ostris/ai-toolkit/blob/main/ui/src/app/api/jobs/%5BjobID%5D/delete/route.ts No existing issues appear to cover this specific error.

Proposed Fix Replace the deprecated call with the modern equivalent fs.rmSync():

if (fs.existsSync(trainingFolder)) {
  // Use rmSync instead of rmdirSync for recursive delete (compatible with Node.js 18+ where recursive was removed from rmdir)
  fs.rmSync(trainingFolder, { recursive: true, force: true });
}
  • fs.rmSync() is the official replacement for recursive directory removal.
  • force: true ensures it doesn't throw if the folder is already partially/fully deleted or doesn't exist.

This change is backward-compatible (works on older Node.js too) and resolves the error immediately. After editing the source file and restarting the UI, job deletion works perfectly.

Steps to Reproduce Start a training job and stop it (or let one complete). In the Training Queue, click the delete button on a stopped job. Check the terminal/log for the TypeError above.

Environment AI-Toolkit: Latest main branch (as of Dec 21, 2025) Node.js: 20+ (common with recent installs; toolkit recommends 18+) OS: Windows (but likely affects any platform with modern Node)

This is a quick, low-risk fix that would improve compatibility for many users. Happy to submit a PR if desired! Thanks for the awesome toolkit! 🚀

camoody1 avatar Dec 21 '25 09:12 camoody1

That really works, thank you so much!

grandmaneedsmorecake avatar Dec 26 '25 17:12 grandmaneedsmorecake