Chartjs-NPM module doesn't work with Webpack 3 but works with vue-cli3 which based on Webpack 4

0šŸ‘

The example code you gave in the beginning: ā€œI paid attention that it doesnā€™t have module.exports = ā€¦ neither export defaultā€

(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' 
? factory(require('chart.js')) 
: typeof define === 'function' && define.amd ? define(['chart.js'], factory) :
    (factory(global.Chart));
}(this, (function (Chart) { 'use strict';
...
})));

Above says:

If on the system this code is running has export as an object and module does exist, do factory(require(ā€˜chart.jsā€™)

ELSE

if define equals function and define.amd exists then define([ā€˜chart.jsā€™], factory)

AND

if none of the above exist just do factory(global.Chart)

Did you do:

ā€œnpm install vue-chartjs chart.js ā€“saveā€

or just

ā€œnpm install vue-chartjs ā€“saveā€

Chart.js is a peer-dependency and needed, the last option will not work.

npm install chartjs ā€“save will do the trick I think

Leave a comment