【问题标题】:require moment define.AMD not working after publishing需要时刻定义。AMD 发布后无法正常工作
【发布时间】:2020-05-04 13:38:10
【问题描述】:

我使用的库有问题。 文件头是:

(function (factory) {
    'use strict';
    if (typeof define === 'function' && define.amd) {
        // AMD is used - Register as an anonymous module.
        define(['jquery', 'moment'], factory);
    } else if (typeof exports === 'object') {
        module.exports = factory(require('jquery'), require('moment'));
    } else {
        // Neither AMD nor CommonJS used. Use global variables.
        if (typeof jQuery === 'undefined') {
            throw 'bootstrap-datetimepicker requires jQuery to be loaded first';
        }
        if (typeof moment === 'undefined') {
            throw 'bootstrap-datetimepicker requires Moment.js to be loaded first';
        }
        factory(jQuery, moment);
    }
}(function ($, moment) {

网上的问题是moment.locale()不是函数。

在控制台中有一个断点,我有:

我的应用程序是 Angular 应用程序,我没有对我的 moment 版本和我使用的库进行任何大的更改。

任何人都可以指出我现在应该检查什么,因为我在这方面浪费了很多时间?

【问题讨论】:

    标签: angular momentjs eonasdan-datetimepicker


    【解决方案1】:

    我的项目在 Vuejs 上,我也使用 bootstrap-datetimepicker。在将 momentjs 更新到 2.25.2 之前它运行良好。现在我看到了同样的错误。

    临时解决方法是将 momentjs 降级到 2.24.0。

    【讨论】:

    • 超级!就是这样
    • 对我来说,2.25.3 解决了这个问题:“2020 年 5 月 4 日发布删除 package.json 模块属性。看起来 webpack 对于通过 module 与 jsnext:main 加载的模块的行为不同。”
    猜你喜欢
    • 2015-06-21
    • 2017-03-06
    • 2016-03-09
    • 1970-01-01
    • 1970-01-01
    • 2021-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多