异常:mkdirp -- "TypeError: invalid options argument"
mkdirp package: https://www.npmjs.com/package/mkdirp
安装:npm i mkdirp --save
源码:
const mkdirp = require('mkdirp');
var path='./xxx';
mkdirp(path, function(err){
if(err){
console.log(err);
return;
}
else{
console.log('pow!');
}
})
报错:
原因:(版本更新导致)mkdirp@1.0.0 no longer supports callbacks and instead uses promises. If you have older code that uses the callback way and don't want to migrate, use mkdirp@0.5.1 It's a better idea to migrate, but it's understandable that migrating code from 4 years ago isn't worth the effort sometimes. https://github.com/isaacs/node-mkdirp#choosing-a-recursive-mkdir-implementation
解决:(参考官方package的使用说明)
mkdirp(path).catch(err =>{console.log(err)}).then(p => console.log(`made dir staring with ${p}`))