Skip to content

How to load via Laravel Mix? #280

@Synchro

Description

@Synchro

I'm trying to get this plugin to work, but really getting nowhere. I have installed it from npm, and configured Laravel mix (webpack front-end) to bundle chart.js and this plugin into a single JS file:

mix.js(
    [
        'node_modules/chart.js/dist/chart.js',
        'node_modules/chartjs-plugin-datalabels/dist/chartjs-plugin-datalabels.js'
    ],
    'public/js/chart.js'
);

I can see that this does indeed include the source of both packages in the target file. I then load that into my page with a script tag. I can create Chart instances with no problems (despite having no import statement relating to it) , but I just can't seem to get the plugin to work at all. The registration syntax in the docs doesn't work for me:

import {ChartDataLabels} from 'chartjs-plugin-datalabels';

SyntaxError: Unexpected token '{'. import call expects exactly one argument.

If I remove the {}, I get:

SyntaxError: Unexpected identifier 'ChartDataLabels'. import call expects exactly one argument.

If I do neither of those, I just get a ReferenceError: Can't find variable: ChartDataLabels when I try to use the plugin.

I'm sure I must be be missing something very basic, but I don't know what.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions