2016-03-08 46 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

相关问题