【问题标题】:An unhandled exception occurred: Script file ../node_modules/chart.js does not exist发生未处理的异常:脚本文件 ../node_modules/chart.js 不存在
【发布时间】:2020-06-09 06:16:21
【问题描述】:

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

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

我在 Angular.json

中添加了../node_modules/chart.js/dist/Chart.js

当我尝试使用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"]
          },

【问题讨论】:

  • 我们需要更多信息来帮助您,您的代码是什么?您是如何尝试导入 chart.js 的?
  • 我做了,我没有写任何代码,我只是尝试在包含这些库后开始我的项目......
  • 能否请您提供 angular.json 的部分是您添加了库吗?
  • 是的,我现在就编辑问题
  • 这对我不起作用。如果我从脚本中删除它,构建将编译,但我的页面上出现运行时错误,即“图表”未定义。

标签: javascript node.js angular primeng


【解决方案1】:

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

只需使用 npm install chart.js --save 安装

问题会解决的

【讨论】:

    【解决方案2】:

    您的 Angular json 中不需要 chartjs 脚本

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

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

    npm install --save @types/chart.js
    

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

    【讨论】:

    • 非常感谢它的工作,我正在关注一个教程,他们说我应该将它包含在我的脚本中,正如你所说我刚刚从我的 Angular.json 的脚本中删除了 "../node_modules/chart.js/dist/Chart.js" :)
    • 太好了,我很高兴能帮上忙:D
    猜你喜欢
    • 2016-04-22
    • 2022-10-22
    • 2021-06-12
    • 2022-06-22
    • 1970-01-01
    • 2016-02-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多