[FIXED] Module not found: Error: Can't resolve 'chart.js' in /node_modules/ng2-charts/fesm2015'

Issue

I am encountering the error:

ERROR in ./node_modules/ng2-charts/fesm2015/ng2-charts.js

Module not found: Error: Can’t resolve ‘chart.js’ in /node_modules/ng2-charts/fesm2015′

I did "npm install –save ng2-charts". Could you help me to understand why this error is thrown?

My package.json

"dependencies": {
"@angular/animations": "~8.2.9",
"@angular/common": "~8.2.9",
"@angular/compiler": "~8.2.9",
"@angular/core": "~8.2.9",
"@angular/fire": "^5.2.3",
"@angular/forms": "~8.2.9",
"@angular/platform-browser": "~8.2.9",
"@angular/platform-browser-dynamic": "~8.2.9",
"@angular/router": "~8.2.9",
"@ngrx/store": "^8.6.0",
"@ngrx/store-devtools": "^8.6.0",
"bootstrap": "^4.4.1",
"firebase": "^7.6.0",
"ng2-charts": "^2.2.3",
"rxjs": "~6.4.0",
"sweetalert2": "^9.5.3",
"tslib": "^1.10.0",
"zone.js": "~0.9.1" }

"devDependencies": {
"@angular-devkit/build-angular": "^0.803.21",
"@angular/cli": "~8.3.8",
"@angular/compiler-cli": "~8.2.9",
"@angular/language-service": "~8.2.9",
"@types/jasmine": "~3.3.8",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "^5.0.0",
"jasmine-core": "~3.4.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.1.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.0",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.15.0",
"typescript": "~3.5.3" }

Error in broswer

enter image description here

Solution

ng2-charts is just an angular wrapper for Chart.js library. Hence the latter also needs to be installed separately.

npm install –save ng2-charts

npm install –save chart.js

Answered By – Arcteezy

Answer Checked By – Laura B. (Easybugfix Admin)

Leave a Reply

(*) Required, Your email will not be published