javascriptnpmelectronrmnode.js-fs

nodejs fs.rm(path, { recursive: true, force: true }) throws "ENOTEMPTY: directory not empty"


import { existsSync } from "fs";
import fs from "fs/promises";

export async function makeFolder(path: string) {
if (existsSync(path)) {
try {
await fs.rm(path, { recursive: true, force: true });
} catch (e) {
console.log("ERROR", e);
}
}
await fs.mkdir(path, { recursive: true });
}

ENOTEMPTY: directory not empty

In the dist/resources folder there is a file called default_app.asar. When deleting the file manually the command works but when it's restored by npm install the error is back. I checked and the file is not used by any process.


Solution

  • The problem was the asar file from the/dist/resources folder.

    Fixed by setting

    process.noAsar = true
    

    Before calling the following function

    fs.rm()