2017-02-14 280 views
0

我一直在使用psd.js和我的懸浮窗reactjs項目配置這樣
PSD.js在反應錯誤fs.readFileSync不是一個函數

accept: function(file, done){ 
     const reader = new FileReader(); 
     reader.onload = handleReaderLoad; 
     reader.readAsDataURL(file); 
     function handleReaderLoad(evt) { 
      console.log(evt.target.result); 
      let psdFile = PSD.fromFile(evt.target.result); 
      psdFile.parse(); 
      console.log(psdFile); 
     } 
     done(); 
     }, 

的錯誤是:

Uncaught TypeError: fs.readFileSync is not a function 
    at Function.fromFile (init.coffee:6) 
    at FileReader.handleReaderLoad (index.js?03a7:153) 

在我的webpack配置我inlclude:

node: { 
    fs: 'empty' 
    }, 

,因爲如果不包含它,錯誤not found fs module

請幫助

回答

0

你應該使用PSD.fromEvent(evt),不PSD.fromFile

前者從文件輸入中讀取blob,而後者試圖打擊瀏覽器上下文中明顯不存在的文件系統。

所以我想你的代碼應該是這樣的(但我不是很確定)

accept: function(file, done){ 
    const reader = new FileReader(); 
    reader.onload = handleReaderLoad; 
    reader.readAsDataURL(file); 
    function handleReaderLoad(evt) { 
     PSD.fromEvent(evt).then(function (psd) { 
      // here you can access the parsed file as psd 
      console.log(psd.tree().export()); 
      done(); 
     }); 
    } 

    }, 
+0

如果我使用'PSD.fromEvent()'的errror是'遺漏的類型錯誤:PSD.fromEvent不FileReader.handleReaderLoad'上的函數 。最新錯誤@pawel – Ariasa

相關問題