SeanSobey / ChartjsNodeCanvas

A node renderer for Chart.js using canvas.
MIT License
230 stars 75 forks source link

chartjs-node-canvas using webpack #104

Open yo34 opened 2 years ago

yo34 commented 2 years ago

Hi,

I using this conf where running webpack :


export default {
  entry: './server.js',
  mode: "production",
  devtool: 'source-map',
  //externals: [nodeExternals({allowlist: [/\.(?!(?:jsx?|json)$).{1,5}$/i],})],
  // la allowlist spécifie les packages qui vont etre dans le bundle
  externals: [nodeExternals({allowlist: [ ...,  'chart.js', 'chartjs-adapter-moment', 'chartjs-node-canvas', 'chartjs-node-canvas']})],

I get the following error where I build the application :


WARNING in ./node_modules/chartjs-node-canvas/dist/freshRequire.js 6:25-46
Critical dependency: the request of a dependency is an expression
 @ ./node_modules/chartjs-node-canvas/dist/index.js 4:23-48
 @ ./graphInit.js 17:0-55 1316:32-49
 @ ./server.js 7:0-38 34:13-41 35:16-42 141:2-28 146:2-29 178:4-39 204:4-39
SeanSobey commented 2 years ago

Hi there!

So I have not used webpack much and am not familiar with that error or why there is a need for webpack on Nodejs actually (is it not meant for browser based js?). From my limited understanding, I assume it is complaining about the 'use' of require in that bit of code, since it is a commonjs module thing? I have not yet added support for esm in this lib, and it will be non-trivial given the node-canvas memory management concerns, but it is on the roadmap.

Not sure if this helped? If it is not related to my assumption maybe you can guide me a bit on the details of why/ how it is breaking?