chartjs / chartjs-plugin-datalabels

Chart.js plugin to display labels on data elements
https://chartjs-plugin-datalabels.netlify.app
MIT License
863 stars 460 forks source link

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

Open andrepintado opened 2 years ago

andrepintado commented 2 years ago

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

simonbrunel commented 1 year ago

@andrepintado It looks like something specific to require.js so it may be better to ask this question in their repository. If you think there is a bug in this library, please provide a way for us to reproduce and debug your issue.