Can't find module Chart.js among node_modules

Hi all, I’m following this tutorial:

I’ve added my dependency with

npm install chart.js --save

But if I import Chart with

import { Chart } from 'chart.js';

in my page “stats” I get this error:

Can’t find module ‘chart.js’

I’ve also tried to import it with

import 'chart.js/src/chart.js';  

into my app.module.ts but with no luck.

Any help?

Thank you in advance.

npm install chartjs --save

Check your node_modules directory for existence of chartjs folder

Tom

1 Like

Hi, you need to have the Chart.js in build folder.
You can try add this in node_modules/@ionic/app-scripts/config/copy.config.js

copyChart: { src: ['{{ROOT}}/node_modules/chart.js/dist/Chart.js'], dest: '{{BUILD}}' }

That solve the problem for me :wink:

1 Like

I assure to you that as I stated before I’ve already launched this exact command.

But, dunno why, it gave me the error I reported in my post.

When I read your post I thought “ok, let’s try again” and launched that command once more .

Error vanished.

I’m increasingly convinced that computer science is related to machine psychology, lol.

Thank you.

Well
There is a slight difference between the command you posted and the one I did

Namely a dot

But glad to see it worked. I am using chartjs and it works perfectly fine

Regards

Tom

1 Like

Ok, I’m ufficialy stupid… I haven’t noticed it yesterday! Thank you again.

It gives me same error while creating android build, any clue what might be the reason for this error.