javascript - 如何解决需要适当加载器的 npm 错误?
问题描述
我用 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。
If you downgrade to version 2.9.4 by changing the version number in your package.json to 2.9.4 and run your install command again or remove the package and use the command install chart.js@2.9.4
. This will most likely resolve your issue
推荐阅读
- python-3.x - How to increment integer variable within logging statement?
- jquery - Flask-SocketIO 动态更新图像
- angular - HttpOnly cookie generated on the server is present in Set-Cookie header but is not being saved while running locally
- clojure - Scheduled execution of a function in Clojure
- xmonad - xmobar 卡在更新中
- email - 野牛解析器在我的代码中返回错误而不是“OK”
- c++ - 如何在另一个函数中但在 IF 语句中启动线程
- python-3.x - OutofMemory NearestNeighbors - Gowers 距离
- c++ - 使用 gcc / g++ 禁用 WPO / LTO
- html - 使用按钮单击更改两个组件的颜色