I would like to use chart.js in aurelia project, but I am getting errors. How to add third-party node packages to aurelia app?
I am using aurelia-cli, BTW
Here is what i did
npm install
In aurelia.json I added the following
"dependencies": [ ..., { "name": "chart.js", "path": "../node_modules/chart.js/dist", "main": "Chart.min.js" } ]
In app.html I am adding a line
<require from="chart.js"></require>
But I get an error message:
vendor-bundle.js:1399 Unhandled rejection Error: Load timeout for modules: template-registry-entry!chart.html,text!chart.html
I tried different things, for example, inserting a chart in app.html
// DIDN'T WORK :-( // app.js import {inject} from 'aurelia-framework'; import {Chart} from 'chart.js'; export class App { static inject() { return [Chart]}; constructor() { this.message = 'Hello World!'; } }
And then, in app.html, I added the following require statement
<require from="Chart"></require>
HERE DECISION
You can check the working example here . Initially, I thought you needed to use the aurelia-chart module, however it is very difficult to use, and therefore I would recommend that you use the Chart.JS package Chart.JS . Here's how to include the chart.js module in your Aurelia application:
npm install
In aurelia.json add the following line to the prepend section
"prepend": [ ..., "node_modules/chart.js/dist/Chart.min.js" ],
In the app.js file (or any other model file) add the line
import {Chart} from 'node_modules/chart.js/dist/Chart.js';
For example, if you want to display a chart on the main page:
// app.js import {Chart} from 'node_modules/chart.js/dist/Chart.js'; export class App { ... }
What is it!