1

Here is my code

var Promise = require('bluebird');
var fse = Promise.promisifyAll(require('fs-extra'));

fse.remove('./myDir').then(function () {
  console.log('Remove myDir done.')
});

I always get TypeError: Cannot read property 'then' of undefined error.

Version:

node: v6.9.2
bluebird: 3.4.7
fs-extra: 1.0.0

I searched and found a similar question but not exactly quite the same, and I tried that answer, unfortunately, it can't solve my problem.

Did I miss anything?

Chen Dachao
  • 1,736
  • 2
  • 21
  • 36
  • It's my fault, I forgot to add `Async`-suffix to `fse.remove` method, the correct way should be `fse.removeAsync`, please see [here](http://bluebirdjs.com/docs/features.html) – Chen Dachao Jan 03 '17 at 08:39

1 Answers1

1

I found the correct way is fse.removeAsync, add Asyncsuffix to fse.remove, please see bluebird API here. Hope it can help others.

Update:

With the latest fs-extra, I don't need to import bluebird anymore. See here, below syntax works well.

// Promise Usage
fs.remove('/tmp/myfile')
.then(() => {
  console.log('success!')
})
.catch(err => {
  console.error(err)
})
Chen Dachao
  • 1,736
  • 2
  • 21
  • 36