应用与 Zeit/pkg 打包后 fs.rmdir 递归停止工作
以下脚本适用于 2 种情况:
- 该脚本直接从节点解包为节点 test.js 运行,并且运行良好
- 脚本运行打包,tmpDir 为空。(大多数删除/评论 fs.appendFileSync 行)
const os = require('os');
const fs = require('fs');
const path = require('path');
var tmpDir = path.join(os.tmpdir(), 'test');
if(!fs.existsSync(tmpDir)){
fs.mkdirSync(tmpDir);
fs.appendFileSync(path.join(tmpDir, 'message.txt'), 'data to append');
}
fs.rmdir(tmpDir, {recursive: true}, function(err){
if(err) throw err;
console.log('finished');
});
否则返回以下错误:
internal/validators.js:117
throw new ERR_INVALID_ARG_TYPE(name, 'string', value);
^
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received an instance of Buffer
at validateString (internal/validators.js:117:11)
at Object.dirname (path.js:583:5)
at isRootPath (pkg/prelude/bootstrap.js:168:26)
at fs.readdir (pkg/prelude/bootstrap.js:850:18)
at _rmchildren (internal/fs/rimraf.js:130:3)
at internal/fs/rimraf.js:117:16
at FSReqCallback.oncomplete (fs.js:154:23) {
code: 'ERR_INVALID_ARG_TYPE'
}
在 Windows 10 上的 node12 和 13 上测试。
任何人都知道解决这个问题?
谢谢!