4

hey folks i'm using the Angular2 CLI and trying to import the chart.js module but every time i run up the server I get a 'cannot find module "chart.js"'

import { Component } from '@angular/core'; import Chart from 'chart.js'; @Component({ selector: 'app-root', templateUrl: './app.component.html' }) export class AppComponent { title = 'Test'; let myChart = new Chart({}); }; 
2
  • Try: import 'chart.js/dist/Chart.min.js'; Assuming you did an npm install of chartjs already. Commented Mar 29, 2017 at 20:45
  • i did npm install it but didn't fix it. I need to import Chart from it's directory Commented Mar 29, 2017 at 20:52

1 Answer 1

2

It looks like you may have incorrectly declared your Chart import

You have:

import Chart from 'chart.js'; 

But it should be:

import { Chart } from 'chart.js'; 

Also check that you have the chart.js npm package installed, if you don't have it properly installed, you can install it with:

npm install chart.js --save 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.