'How do I add chartjs into a custom plugin in moodle

I am creating a custom plugin in moodle and I have successfully integrated chartjs (https://www.chartjs.org/). It works perfectly in my development environment when the cache is disabled. But when I turn on my cache below error appears in the console.

enter image description here

enter image description here

local_mql is my custom plugin and the js file is added under amd/src/mql.js and minified version is under amd/build/mql.min.js.

Below is my code.

requirejs.config({
    paths: {
        "chartjs": "https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.min"
    }
});

define(
[
    'jquery',
    'core/str',
    'core/ajax',
    'core/templates',
    'jqueryui',
    'core/modal_factory',
    'core/modal_events',
    'chartjs'
],
function (
    $,
    Str,
    ajax,
    templates,
    jqui,
    ModalFactory,
    ModalEvents,
    Chart
){});

What am I doing wrong? And how do I fix this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source