节点 fs rmdir TypeError 'Callback must be a function'
Node fs rmdir TypeError 'Callback must be a function'
当使用 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
当使用 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