[Chartjs]-Chart.js – Moment.js could not be found! You must include it before Chart.js to use the time scale

3πŸ‘

The Chart.js has the following two versions:

Stand-Alone Build

Files:

dist/Chart.js
dist/Chart.min.js

Bundled Build

Files:

dist/Chart.bundle.js
dist/Chart.bundle.min.js

The Stand-Alone Build does not include moment.js and you have to include it but the Bundled Build includes the moment.js.

Adding the bundled version will include and fix the problem:

<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.bundle.min.js"></script>

1πŸ‘

One way of getting around the CORS problem is requesting the data to the client side as padded JSON. Here is an npm package to do so: https://www.npmjs.com/package/fetch-jsonp

It will return your data as a promise and then you just have to call .json() on it to get back JSON without padding:

fetchJsonp('http://internal-address:5000/api/service_info/tt?severity=2')
.then(data => data.json())
.then(data => console.log(data))

Sounds like that might be a bandaid, but it could get you unstuck for now.

0πŸ‘

Maybe try yarn add instead of npm install. Your issue reminds me of a similar one I had that was likely solved this way IIRC.

-1πŸ‘

May be you can delete package-lock.json and do a npm install again, then build again and see if the problem still exists.

Leave a comment