Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: callback is not a function when removing directory

When I try to remove an existing directory (and its files inside) with fs.rm('./temp/', { recursive: true, force: true }); it succesfully remove it but it throws this error:

node:internal/fs/rimraf:60
    callback(err);
    ^

TypeError: callback is not a function
    at CB (node:internal/fs/rimraf:60:5)
    at FSReqCallback.oncomplete (node:fs:188:23)

I have Node v16.13.2 installed. Thanks!

like image 215
La-lo-go Avatar asked Sep 14 '25 13:09

La-lo-go


1 Answers

due to the node.js fs documentation https://nodejs.org/api/fs.html#fsrmpath-options-callback

you must pass a callback function fs.rm(path[, options], callback)

so your code will look like this:

fs.rm('./temp/', { recursive: true, force: true }, (error) => {
    //you can handle the error here
});
like image 153
1sina1 Avatar answered Sep 17 '25 02:09

1sina1