# How to integrate amCharts4 in Aurelia CLI v2.0.2 using Require.js

**URL:** https://discourse.aurelia.io/t/how-to-integrate-amcharts4-in-aurelia-cli-v2-0-2-using-require-js/4019
**Category:** Help Requests
**Created:** [February 5, 2021, 10:33am UTC](https://discourse.aurelia.io/t/how-to-integrate-amcharts4-in-aurelia-cli-v2-0-2-using-require-js/4019 "2021-02-05T10:33:48Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![alextalmazan](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/alextalmazan/32/1635_2.png) [@alextalmazan](https://discourse.aurelia.io/u/alextalmazan)
#### Post date: [February 5, 2021, 10:33am UTC](https://discourse.aurelia.io/t/how-to-integrate-amcharts4-in-aurelia-cli-v2-0-2-using-require-js/4019/1 "2021-02-05T10:33:48Z")

</div>

Does anyone know how to configure amCharts4 in Aurelia CLI v2.0.2 using Require.js?

I’ve tried installing it using npm and using it directly but I get this error:

```
[PackageAnalyzer] The "@amcharts/amcharts4" package has no valid main file, fall back to index.js.
```

---

<div class="post-metadata">

### Author: ![huochunpeng](https://avatars.discourse-cdn.com/v4/letter/h/49beb7/32.png) [@huochunpeng](https://discourse.aurelia.io/u/huochunpeng)
#### Post date: [February 6, 2021, 2:14am UTC](https://discourse.aurelia.io/t/how-to-integrate-amcharts4-in-aurelia-cli-v2-0-2-using-require-js/4019/2 "2021-02-06T02:14:13Z")

</div>

The npm package is strange, it doesn’t have “main” field in package.json.

If you follow the doc [Using TypeScript or ES6 – amCharts 4 Documentation](https://www.amcharts.com/docs/v4/getting-started/using-typescript-or-es6/)  
it asks you to import internal files directly. (If you import `@amcharts/amcharts4`, bundler will try to load main file which doesn’t exist.).

```auto
import * as am4core from "@amcharts/amcharts4/core";
import * as am4charts from "@amcharts/amcharts4/charts";

```

The other option is to use prepend [https://aurelia.io/docs/cli/cli-bundler/dependency-management#prepend](https://aurelia.io/docs/cli/cli-bundler/dependency-management#prepend) to load

```auto
"node_modules/@amcharts/amcharts4/core.js",
"node_modules/@amcharts/amcharts4/charts.js",

```

As legacy lib, then use global vars `am4core` and `am4charts` directly.

---

<div class="post-metadata">

### Author: ![alextalmazan](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/alextalmazan/32/1635_2.png) [@alextalmazan](https://discourse.aurelia.io/u/alextalmazan)
#### Post date: [February 8, 2021, 2:12pm UTC](https://discourse.aurelia.io/t/how-to-integrate-amcharts4-in-aurelia-cli-v2-0-2-using-require-js/4019/3 "2021-02-08T14:12:06Z")

</div>

Thank you @huochunpeng . I’ve tried your suggested approach with prepend and it does not seem to work, there aren’t any build errors but the global variables does not seem to be there. I tried as well the second approach using Shim [https://aurelia.io/docs/cli/cli-bundler/dependency-management#shim](https://aurelia.io/docs/cli/cli-bundler/dependency-management#shim) and it can’t find the files in the path specified.

---

<div class="post-metadata">

### Author: ![huochunpeng](https://avatars.discourse-cdn.com/v4/letter/h/49beb7/32.png) [@huochunpeng](https://discourse.aurelia.io/u/huochunpeng)
#### Post date: [February 9, 2021, 2:08am UTC](https://discourse.aurelia.io/t/how-to-integrate-amcharts4-in-aurelia-cli-v2-0-2-using-require-js/4019/4 "2021-02-09T02:08:39Z")

</div>

My bad, just checked the package, there is build error for me if I put it in prepend

```auto
 "prepend": [
          "node_modules/@amcharts/amcharts4/core.js",
          "node_modules/@amcharts/amcharts4/charts.js",
          "node_modules/regenerator-runtime/runtime.js",
          "node_modules/promise-polyfill/dist/polyfill.min.js",
          "node_modules/requirejs/require.js"
        ],

```

The bundler complains keyword “export” because amcharts4 shipped code in ESM format.

Unfortunately,

```auto
import * as am4core from "@amcharts/amcharts4/core";
import * as am4charts from "@amcharts/amcharts4/charts";

```

does not work either because cli-bundler uses esprima which doesn’t understand some of amcharts’s new js syntax (I guess amcharts compiled to quite latest JS syntax).

I tested with [dumber bundler](https://dumber.js.org) (The successor of cli-bundler, Aurelia 2 moved from cli-bundler to dumber). The above imports works with dumber.

For cli-bundler, the only option right now is to use CDN in your html head, that will give you the global vars.

```auto
<script src="https://cdn.amcharts.com/lib/4/core.js"></script>
<script src="https://cdn.amcharts.com/lib/4/charts.js"></script>

```
