2017-01-03 21 views
1

這裏是我的代碼`FS-extra`與整合``藍鳥了undefined`錯誤的`無法讀取屬性 '然後'

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

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

我總是TypeError: Cannot read property 'then' of undefined錯誤。

版本:

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

我搜索,發現類似question,但不完全完全一樣的,我試過了答案,不幸的是,它解決不了我的問題。

我錯過了什麼嗎?

+0

這是我的錯,我忘了Async'後綴添加到''fse.remove'方法,正確的做法應該是'fse.removeAsync',請參見[這裏](HTTP:// bluebirdjs。 com/docs/features.html) –

回答

0

我發現正確的方法是fse.removeAsync,加Async後綴到fse.remove,請看藍鳥API here。希望它能幫助別人。

更新:

隨着最新fs-extra,我並不需要進口bluebird了。 請參閱here,以下語法運行良好。

// Promise Usage 
fs.remove('/tmp/myfile') 
.then(() => { 
    console.log('success!') 
}) 
.catch(err => { 
    console.error(err) 
}) 
+0

你現在應該接受你的答案。 –

相關問題