gpt4 book ai didi

javascript - 如何解决需要适当加载器的 npm 错误?

转载 作者:行者123 更新时间:2023-12-03 08:23:33 25 4
gpt4 key购买 nike

我使用 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

应用程序.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
},
}

折线图.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>

...................................................... ...................................................... ...................................................... ...................................................... ...................................................... ...................................................... …………

最佳答案

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

如果您通过将 package.json 中的版本号更改为 2.9.4 降级到版本 2.9.4,然后再次运行安装命令或删除包并使用命令 install <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e7848f869593c98d94a7d5c9dec9d3" rel="noreferrer noopener nofollow">[email protected]</a> 。这很可能会解决您的问题

关于javascript - 如何解决需要适当加载器的 npm 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67134092/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com