chartjs / chartjs/chartjs-plugin-datalabels

chartjs-plugin-datalabels with requirejs (ReferenceError: module is not defined)

Open
#314 1 comment 0 reactions 0 assignees View on GitHub
needs test case
Dominant language
JavaScript
Stars
920
Forks
507
PR merge metrics
No merged PRs in 30d

Description

Hello guys,

I'm currently trying to set up chartjs 3 + chartjs datalabels 2 along with requirejs, and I'm getting the following errors:
```
helpers.js:1 Uncaught ReferenceError: module is not defined

chartjs-plugin-datalabels.min.js:7 Uncaught TypeError: Cannot read properties of undefined (reading 'merge')
```

Here's my requirejs config:
```
requirejs.config({
paths: {
'chartjs': '../vendor/chart.js/dist/chart.min',
'chartjs-plugin-datalabels': '../vendor/chartjs-plugin-datalabels/dist/chartjs-plugin-datalabels.min',
},

shim: {
'chartjs-plugin-datalabels': {
deps: ['chartjs']
},
},

map: {
'chartjs-plugin-datalabels': {
"chart.js": "chartjs",
"chart.js/helpers": "../vendor/chart.js/helpers/helpers"
}
}
});
```

Everything was working well with chartjs 2 + chartjs datalabels 1, but with this upgrade, it's not anymore. I'm guessing it has to do with the `module.exports = require('..').helpers;` in helpers.js, but I don't know how to fix this.

Can you help me?
Thanks a lot

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the reported setup with the supplied RequireJS paths, shim, and map configuration. Inspect helpers.js and dist/chartjs-plugin-datalabels.min.js alongside the Chart.js 3 loading entry points to determine the module-format mismatch. Done means the RequireJS setup loads Chart.js and the datalabels plugin without either reported error and the plugin functions as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
chart.js, javascript
Domain
frontend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.