【问题标题】:moment-isocalendar not working时刻等日历不起作用
【发布时间】:2013-08-13 15:24:48
【问题描述】:

根据他们的文档,需要做的就是需要 moment-isocalendar 模块。

这不起作用:

var m = require("moment");
var i = require("moment-isocalendar");
m().isocalendar();

它抛出

TypeError: Object Tue Aug 13 2013 18:20:36 GMT+0300 has no method 'isocalendar'
    at repl:1:6
    at REPLServer.self.eval (repl.js:110:21)
    at Interface.<anonymous> (repl.js:239:12)
    at Interface.EventEmitter.emit (events.js:95:17)
    at Interface._onLine (readline.js:202:10)
    at Interface._line (readline.js:531:8)
    at Interface._ttyWrite (readline.js:760:14)
    at ReadStream.onkeypress (readline.js:99:10)
    at ReadStream.EventEmitter.emit (events.js:98:17)
    at emitKey (readline.js:1095:12)

我查看了模块(所有模块都使用npm 安装),它需要“时刻”并对其进行猴子补丁。我尝试在moment 模块之前要求moment-isocalendar,但得到了相同的结果。 moment-isocalendar 是猴子补丁 {} 之后的一个空对象。

以前有人在 nodejs 中使用过 momentjs 插件吗?任何想法如何使这项工作?

稍后编辑

它适用于 nodejs v0.10.12,它不适用于 nodejs v0.10.15。我添加了一个答案。

稍后编辑

我正在运行带有 3.8.0-26-generic 内核的 Ubuntu 13.04,并且 nodejs 是通过 ppa:chris-lea/node.js 的包管理器安装的

【问题讨论】:

  • 这在 v0.10.15 中适用于我

标签: node.js date datetime momentjs


【解决方案1】:

moment-isocalendar 是一个插件,不是moment.js 主库的一部分。我的猜测是他们在最后一刻没有更新它。js 版本,但我没有验证这一点。

您应该在这里提出问题:https://github.com/fusionbox/moment-isocalendar

【讨论】:

    【解决方案2】:

    经过一番研究,答案很简单:它不起作用。它依赖于较旧的 nodejs 功能(错误),您可以在内存模块的第一个 require 之后对其进行猴子修补,这显然不再有效(在 0.10.12 中有效,在 0.10 中无效。 15).

    如果有人按原样获得模块,我会更改正确答案。

    【讨论】:

    • 感谢您的评论,我还没有成功。只是我问题中的三行代码,它们在 0.10.12 中在我的机器上运行,并在 0.10.15 中抛出错误:/
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-03
    • 1970-01-01
    • 1970-01-01
    • 2013-12-05
    • 2018-04-06
    相关资源
    最近更新 更多