发生未处理的异常:脚本文件 ../node_modules/chart.js 不存在

Yas*_*aki 4 javascript node.js primeng angular

我正在尝试在我的 Angular 项目中使用 PrimeNG,我创建了一个新项目并尝试启动,但它给了我这个错误,我执行了以下步骤:

  1. npm install primeng --save
  2. npm install @angular/animations --save
  3. npm install Chart.js --save
  4. npm uninstall ng2-charts

我../node_modules/chart.js/dist/Chart.js在我的Angular.json 中添加

当我尝试使用 运行我的项目时ng serve,它给了我以下错误:

发生未处理的异常:脚本文件 ../node_modules/chart.js 不存在

任何帮助都可能有用,谢谢。

编辑:

这是我的 Angular.json 的一部分:

"architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/YarbiTkhdem",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "aot": true,
            "assets": ["src/favicon.ico", "src/assets"],
            "styles": ["src/styles.css"],
            "scripts": ["../node_modules/chart.js/dist/Chart.js"]
          },
Run Code Online (Sandbox Code Playgroud)

小智 7

您不需要角度 json 中的 chartjs 脚本

“脚本”:[“../node_modules/chart.js/dist/Chart.js”]

您可以使用以下命令向 charjs 添加输入:

npm install --save @types/chart.js
Run Code Online (Sandbox Code Playgroud)

https://www.npmjs.com/package/@types/chart.js

  • 非常感谢它有效,我正在遵循一个教程,他们说我应该将其包含到我的脚本中,正如你所说我刚刚从脚本中删除了“../node_modules/chart.js/dist/Chart.js”`我的“Angular.json”:) (2认同)