最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - TypeError: callback is not a function when removing directory - Stack Overflow

programmeradmin1浏览0评论

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.onplete (node:fs:188:23)

I have Node v16.13.2 installed. Thanks!

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.onplete (node:fs:188:23)

I have Node v16.13.2 installed. Thanks!

Share Improve this question edited Jan 25, 2022 at 11:37 La-lo-go asked Jan 25, 2022 at 11:12 La-lo-goLa-lo-go 3002 silver badges13 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

due to the node.js fs documentation https://nodejs/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
});
发布评论

评论列表(0)

  1. 暂无评论