【问题标题】:How to resolve npm error needing an appropriate loader?如何解决需要适当加载器的 npm 错误?
【发布时间】:2021-04-17 02:17:10
【问题描述】:

我用 vue-chartjs 创建了一个 Vue.js 项目。我尝试重新安装库,但仍然出现此错误:

error  in ./node_modules/chart.js/dist/chart.esm.js
Module parse failed: Unexpected token (6613:12)
You may need an appropriate loader to handle this file type.
|         if (intermediateIndex1 !== startIndex && intermediateIndex1 !== lastIndex) {
|           decimated.push({
|             ...data[intermediateIndex1],
|             x: avgX,
|           });
 @ ./node_modules/vue-chartjs/es/BaseCharts.js 1:0-29
 @ ./node_modules/vue-chartjs/es/index.js

App.vue:

<template>
  <div id="app"></div>
</template>

<script>
import axios from "axios";
import moment from "moment";
import LineChart from "./components/LineChart";

export default {
  name: "App",
  components: {
    LineChart
  },
}

LineChart.vue

<script>
import { Line } from "vue-chartjs";

export default {
  extends: Line,
  props: {
    label: {
      type: String
    },
    chartData: {
      type: Array
    },
    options: {
      type: Object
    },
  },
  mounted() {
    const dates = this.chartData.map(d => d.date).reverse();
    const totals = this.chartData.map(d => d.total).reverse();

    this.renderChart(
      {
        labels: dates,
        datasets: [
          {
            label: this.label,
            data: totals
          }
        ]
      },
      this.options
    );
  }
};
</script>

.................................................. ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ......

【问题讨论】:

    标签: javascript vue.js npm chart.js vue-chartjs


    【解决方案1】:

    很有可能你安装了 chartjs 版本 3。vue 包装器与此版本的 chart.js 不兼容,仅支持旧版本 2。

    如果您通过将 package.json 中的版本号更改为 2.9.4 降级到版本 2.9.4 并再次运行安装命令或删除包并使用命令 install chart.js@2.9.4 。这很可能会解决您的问题

    【讨论】:

    • 感谢您的回复。我会尝试使用其他版本。
    猜你喜欢
    • 2018-01-08
    • 2018-06-10
    • 1970-01-01
    • 2018-05-07
    • 1970-01-01
    • 2019-09-24
    • 2016-03-15
    • 2023-03-21
    • 2018-05-21
    相关资源
    最近更新 更多