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

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

我遇到错误:

错误在 ./node_modules/ng2-charts/fesm2015/ng2-charts.js

找不到模块:错误:无法在 /node_modules/ng2-charts/fesm2015'[=12 中解析 'chart.js' =]

我做了“npm install --save ng2-charts”。你能帮我理解为什么会抛出这个错误吗?

我的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" }

浏览器出错

ng2-charts 只是 Chart.js 库的 angular 包装器。因此后者也需要单独安装

npm install --save ng2-charts

npm install --save chart.js

尝试安装更高版本的chartjs,我安装的是旧版本 尝试“npm install chartjs@3.7.1”