作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用 fs.rmdir
时函数我从 Ubuntu 得到这个错误:
fs.js:136
throw new ERR_INVALID_CALLBACK();
^
TypeError [ERR_INVALID_CALLBACK]: Callback must be a function
at makeCallback (fs.js:136:11)
at Object.rmdir (fs.js:671:14)
<...>
我不确定这是什么原因,因为当我在我的 Windows 10 计算机上本地测试它时它工作得非常好。
// remove client's temporary directory and its files
fs.rmdir('temp/' + socketID, {recursive: true}, (error) => {
if(error) throw error;
});
另外,在 Ubuntu 机器上,如果我删除
{recursive: true}
选项,命令确实运行并且回调工作,但它没有解决问题,因为我想要递归选项。
最佳答案
您显然在那台机器上运行旧版本的 nodejs,它不支持选项的第二个参数,因此它认为您在它期望回调的地方传递选项对象。
检查您的 nodejs 版本。您至少需要 v12.10 才能获得对递归选项的支持。根据您报告的错误,您的版本似乎是 v10 或更高版本,但低于 v12.10。更新你的 nodejs 安装,你应该很好。
这是fs.rmdir()
的发展历程:
v13.3.0, v12.16.0
The maxBusyTries option is renamed to maxRetries, and its default is 0.
The emfileWait option has been removed, and EMFILE errors use the same retry logic as
other errors. The retryDelay option is now supported. ENFILE errors are now retried.
v12.10.0
The recursive, maxBusyTries, and emfileWait options are now supported.
v10.0.0
The callback parameter is no longer optional. Not passing it will throw a TypeError
at runtime.
v7.6.0
The path parameters can be a WHATWG URL object using file: protocol. Support is currently
still experimental.
v7.0.0
The callback parameter is no longer optional. Not passing it will emit a deprecation
warning with id DEP0013.
v0.0.2
Added in: v0.0.2
关于node.js - Node fs rmdir 类型错误 'Callback must be a function',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65931745/
我是一名优秀的程序员,十分优秀!