首页 > 解决方案 > 安装 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 安装和使用的说明。

谢谢

标签: javascriptd3.jses6-modulesc3.js

解决方案


固定的:

-import * as c3 from 'c3'

+从'c3'导入c3


推荐阅读