javascript - 安装 c3 以在带有 ES6 导入的 webpack 项目中使用的正确程序是什么?
问题描述
我有一个非常简单的 webpack 项目,它使用 Html 插件从单个 js 文件条目生成 html 文件。
我用“npm install c3”安装了c3
图表.js
import * as c3 from "c3";
var chart = c3.generate({
bindto: '#chart',
data: {
columns: [
['data1', 30, 200, 100, 400, 150, 250],
['data2', 50, 20, 10, 40, 15, 25]
]
}
});
当我加载页面时出现错误:
bootstrap:893 TypeError: c3.generate is not a function
at chart.js:5
at chart.js:14
__webpack_require__.oe @ bootstrap:893
Promise.catch (async)
./client/chart.js @ chart.js:14
__webpack_require__ @ bootstrap:769
fn @ bootstrap:129
6 @ module.js:22
__webpack_require__ @ bootstrap:769
(anonymous) @ bootstrap:907
(anonymous) @ bootstrap:907
chart.js:5 Uncaught (in promise) TypeError: c3.generate is not a function
at chart.js:5
at chart.js:14
(anonymous) @ chart.js:5
(anonymous) @ chart.js:14
Promise.catch (async)
./client/chart.js @ chart.js:14
__webpack_require__ @ bootstrap:769
fn @ bootstrap:129
6 @ module.js:22
__webpack_require__ @ bootstrap:769
(anonymous) @ bootstrap:907
(anonymous) @ bootstrap:907
我的 package.json 包含
"dependencies": {
"@types/c3": "^0.7.4",
"c3": "^0.7.12",
非常感谢任何建议。c3js.org 没有给出如何通过 ES6 导入进行 npm 安装和使用的说明。
谢谢
解决方案
固定的:
-import * as c3 from 'c3'
+从'c3'导入c3
推荐阅读
- find - 如何以编程方式将引号添加到 Windows 文件/目录名称 w
- spring - 无效的设置方法。setter 的参数类型是否与 getter 的返回类型匹配?
- javascript - 未捕获的类型错误:无法读取 XMLHttpRequest.http.onload 处未定义的属性“状态”
- r - Area plot using R tidyverse, ggplot, geom_area
- sharepoint - 无法通过 Graph API 对共享点列表文件夹应用过滤器,自定义列也不会通过 Graph API 出现
- python - 在 Visual Studio Code 中导入 pyodbc
- javascript - 如何使 JavaScript 模块在 IE 11 中工作
- swift - 使用 CVPixelBuffer 是创建 CAMetalTexture(MTLTexture) 的唯一方法吗?
- c++ - 有没有办法将向量放入括号中
- android-studio - android studio中的蓝屏消失了