0
votes

We want to include Chart.js & jQuery in our Ionic/Angular project.

After installing through npm, we try to reference the files below like usual business:

<script src="../node_modules/chart.js/dist/Chart.min.js"></script>

What are we doing wrong? We have also included a reference for just some reason in packages.json:

  "scripts": {
    ...
    "chart": "../node_modules/chart.js/dist/Chart.js"

If we use the CDN, it works... But why would I even use the npm to install things then? I don't get it...

  • "@ionic-native/core": "~4.12.0"
  • Ionic CLI version 6.4.1
  • "ionic-angular": "3.9.2" We recieve the faulty message as seen below:

Refused to execute script from 'http://localhost:8100/node_modules/jquery/dist/jquery.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

Complete error output:

Error: Uncaught (in promise): ReferenceError: Chart is not defined ReferenceError: Chart is not defined at UIChart.webpackJsonp.500.UIChart.initChart (http://localhost:8100/build/0.js:173:26) at UIChart.webpackJsonp.500.UIChart.ngAfterViewInit (http://localhost:8100/build/0.js:154:14) at callProviderLifecycles (http://localhost:8100/build/vendor.js:13123:18) at callElementProvidersLifecycles (http://localhost:8100/build/vendor.js:13090:13) at callLifecycleHooksChildrenFirst (http://localhost:8100/build/vendor.js:13073:29) at checkAndUpdateView (http://localhost:8100/build/vendor.js:14228:5) at callViewAction (http://localhost:8100/build/vendor.js:14570:21) at execComponentViewsAction (http://localhost:8100/build/vendor.js:14502:13) at checkAndUpdateView (http://localhost:8100/build/vendor.js:14225:5) at callWithDebugContext (http://localhost:8100/build/vendor.js:15473:42) at c (http://localhost:8100/build/polyfills.js:3:19752) at c (http://localhost:8100/build/polyfills.js:3:19461) at http://localhost:8100/build/polyfills.js:3:20233 at t.invokeTask (http://localhost:8100/build/polyfills.js:3:15660) at Object.onInvokeTask (http://localhost:8100/build/vendor.js:5126:33) at t.invokeTask (http://localhost:8100/build/polyfills.js:3:15581) at r.runTask (http://localhost:8100/build/polyfills.js:3:10834) at o (http://localhost:8100/build/polyfills.js:3:7894)

A friend suggested we maybe need to install Browserify or Webpack. Gonna try that...

1

1 Answers

0
votes

If you use chart js through node_modules you don't need to include through <script src="">

When you execute ionic serve you load the node_modules and execute them.

Also you try to use npm start instead of ionic serve to check if can fix your problem. Let me know how it is going.