0

I'm trying to get started with ng2-charts. I've never seen a .js embed from the node_modules directory before, as they specify here:

<script src="node_modules/chart.js/src/chart.js"></script>

I'm using Angular CLI. As far as I understood, the node_modules directory isn't served, and if it is, I do not know how to access it.

I did try duplicating those packages and linking to them in src/, but I get:

Uncaught ReferenceError: require is not defined
    at chart.js:4

I have no clue how this is supposed to work, so I tried to find a working example. Even in the project on Github, the only examples of this embed are in the ReadMe files.

BBaysinger
  • 6,614
  • 13
  • 63
  • 132
  • My guess: chart.js uses nodejs as a base which means that you need that for require to exist. Since you are referencing it from template i would try to reference it from inside your app.js – 404answernotfound Jan 02 '17 at 07:10
  • Have you added your library `chart.js` in `map` like this: `'ng2-select': 'node_modules/ng2-select',`? – Avnesh Shakya Jan 02 '17 at 07:10
  • try following this documentation and let us know: http://www.chartjs.org/docs/#getting-started – 404answernotfound Jan 02 '17 at 07:12
  • Did you ever solve this ? I am trying to get bg2-charts working in an Angular2 app and I am getting the same error. So far, every solution I have found online has failed. – Craig Mar 13 '17 at 02:09
  • import { Chart } from 'chart.js'; – BBaysinger Mar 13 '17 at 18:05

0 Answers0