2016-03-08 34 views
0

我已經用Electron編寫了一個應用程序,一切都在開發環境中工作。打包電子應用程序後無效的日期錯誤

electron-packager我有無效的日期後...

import React, { Component, PropTypes } from 'react'; 
import moment from 'moment'; 

[...] 

render() { 
    const { code } = this.props; 

    moment.locale('fr'); 

    return (
     <div className="ViewCode"> 
      <header> 
       { code.code } 
       <span style={{flex: 1}}></span> 
       <i className="fa fa-pencil-square-o"></i> 
       <i className="fa fa-trash" onClick={this.handleDelete.bind(this)}></i> 
      </header> 
      <article> 
       <div>Name { code.code }</div> 
       <div>Expiration Date { moment(code.expirationDate).format('LLLL') }</div> 
       <div>Max use { code.maxUse }</div> 
       <div>Max use by user { code.maxUseByUser }</div> 
       <div>Action { code.action }</div> 
       <div>Number of use { code.users.length }</div> 
      </article> 
     </div> 
    ) 

} 

} 

包裝前:jeudi 31 décembre 2015 00:59

包裝後:Invalid Date

任何想法?

+0

這可能是一個需要的軟件包安裝在devDependencies下。查看你的package.json文件並檢查你的依賴關係。 – apxp

回答

0

看起來像code.expirationDate不是日期對象,您可以檢查其生命週期。或者只是顯示別的東西,如果沒有有效日期:

render() { 

    const { code } = this.props; 

    moment.locale('fr'); 

    if(!code.expirationDate instanceof Date) { 

     return <div>something</div>; 

    } else { 

     return (
      <div className="ViewCode"> 
       <header> 
        { code.code } 
        <span style={{flex: 1}}></span> 
        <i className="fa fa-pencil-square-o"></i> 
        <i className="fa fa-trash" onClick={this.handleDelete.bind(this)}></i> 
       </header> 
       <article> 
        <div>Name { code.code }</div> 
        <div>Expiration Date { moment(code.expirationDate).format('LLLL') }</div> 
        <div>Max use { code.maxUse }</div> 
        <div>Max use by user { code.maxUseByUser }</div> 
        <div>Action { code.action }</div> 
        <div>Number of use { code.users.length }</div> 
       </article> 
      </div> 
     ); 
    } 
} 

不要猶豫,用BrowserWindow.openDevTools()console.log幫你調試這些類型的錯誤。

+0

你的回答並不清楚,爲什麼日期格式化在測試環境中打包之前工作。 – apxp

+0

好吧,沒有看到'code.expirationDate'在哪裏實例化,我不能說,我確信唯一沒有定義的。那麼,爲什麼這可能是你數據生命週期中的某個地方,也許你可以提供一些其他的代碼? – KeitIG

相關問題