flatpickr - Uncaught ReferenceError: exports is not defined

3k Views Asked by At

I´m trying to use locale for the plugin: flatpickr

Console says:

Uncaught ReferenceError: exports is not defined

This is my code:

HTML

<input type='text' class="form-control dateTime" name="startDateTime" placeholder="Start.."/>

JS

//DateTime
$('.dateTime').flatpickr({
    'locale': 'sv',
    mode: 'multiple',
    defaultHour: '22',
    enableTime: 'true',
    time_24hr: 'true',
});

sv.js

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var fp = (typeof window !== "undefined" && window.flatpickr !== undefined) ? window.flatpickr : {
    l10ns: {},
};
exports.Swedish = {
    firstDayOfWeek: 1,
    weekAbbreviation: "v",
    weekdays: {
        shorthand: ["Sön", "Mån", "Tis", "Ons", "Tor", "Fre", "Lör"],
        longhand: [
            "Söndag",
            "Måndag",
            "Tisdag",
            "Onsdag",
            "Torsdag",
            "Fredag",
            "Lördag",
        ],
    },
    months: {
        shorthand: [
            "Jan",
            "Feb",
            "Mar",
            "Apr",
            "Maj",
            "Jun",
            "Jul",
            "Aug",
            "Sep",
            "Okt",
            "Nov",
            "Dec",
        ],
        longhand: [
            "Januari",
            "Februari",
            "Mars",
            "April",
            "Maj",
            "Juni",
            "Juli",
            "Augusti",
            "September",
            "Oktober",
            "November",
            "December",
        ],
    },
    ordinal: function () {
        return ".";
    },
};
fp.l10ns.sv = exports.Swedish;
exports.default = fp.l10ns;

What might be the problem?

I´ve tried to change order and load the locale file before the js.br> I have also tried to skip the file sv.js and import this code into my main js.

    firstDayOfWeek: 1,
    weekAbbreviation: "v",
    weekdays: {
        shorthand: ["Sön", "Mån", "Tis", "Ons", "Tor", "Fre", "Lör"],
        longhand: [
            "Söndag",
            "Måndag",
            "Tisdag",
            "Onsdag",
            "Torsdag",
            "Fredag",
            "Lördag",
        ],
    },
    months: {
        shorthand: [
            "Jan",
            "Feb",
            "Mar",
            "Apr",
            "Maj",
            "Jun",
            "Jul",
            "Aug",
            "Sep",
            "Okt",
            "Nov",
            "Dec",
        ],
        longhand: [
            "Januari",
            "Februari",
            "Mars",
            "April",
            "Maj",
            "Juni",
            "Juli",
            "Augusti",
            "September",
            "Oktober",
            "November",
            "December",
        ],
    },
1

There are 1 best solutions below

0
On BEST ANSWER

My solution: Skip the sv.js file and add locale{} in main js.

//DateTime
$('.dateTime').flatpickr({
    mode: 'multiple',
    defaultHour: '22',
    enableTime: 'true',
    time_24hr: 'true',
    locale: {
        firstDayOfWeek: 1,
        weekAbbreviation: "v",
        weekdays: {
            shorthand: ["Sön", "Mån", "Tis", "Ons", "Tor", "Fre", "Lör"],
            longhand: [
                "Söndag",
                "Måndag",
                "Tisdag",
                "Onsdag",
                "Torsdag",
                "Fredag",
                "Lördag",
            ],
        },
        months: {
            shorthand: [
                "Jan",
                "Feb",
                "Mar",
                "Apr",
                "Maj",
                "Jun",
                "Jul",
                "Aug",
                "Sep",
                "Okt",
                "Nov",
                "Dec",
            ],
            longhand: [
                "Januari",
                "Februari",
                "Mars",
                "April",
                "Maj",
                "Juni",
                "Juli",
                "Augusti",
                "September",
                "Oktober",
                "November",
                "December",
            ],
        },
    }
});