@types/chart.js package and had problems.I am using Angular 9.0 with ng2-charts.
I have also installed chart.js
A few days ago I was able to develop my app without problems. Now when I try to run ng serve or ng build I get the error:
ERROR in node_modules/@types/chart.js/index.d.ts:32:24 - error TS2307: Cannot find module 'moment'
I look in the index.d.ts and I see that the import is failing. I also noticed that in my node_modules directory there is a directory called moment. If I type import { Moment } from '../../moment/moment in the @types/chart.js/index.d.ts, everything works. Both ng serve and ng build run successfuly.
I know that correcting node_modules locally is not a good fix because when I send the code to my colleagues via Git it won't have the fix in there. Also, when we deploy to our production servers, npm install will run and as a result a broken version of @types/chart.js will be installed.
I didn't know what is the correct permanent fix so this is why I am submitting an issue and not a pull request.
Thank you in advance,
Andreas
If no one else gets back to you I鈥檒l do some research and take a stab at this on monday. Seens odd it would just suddenly break. I鈥檒l go through the commit history.
Do you use moment in your project and / or charts?
Could this happen because someone added a test for a time Chart in the latest release? #44275
@adripanico got any idea?
I updated to 2.9.20 in my own project like 2 days ago but don鈥檛 have any moment issues.
This issue is a moment=2.25.0 bug. It seems to be fixed in 2.25.1.
https://github.com/moment/moment/pull/5487#issuecomment-622492292
If no one else gets back to you I鈥檒l do some research and take a stab at this on monday. Seens odd it would just suddenly break. I鈥檒l go through the commit history.
Do you use
momentin your project and / or charts?
Hello @lekoaf ,
In my project I only use Radar Chart from ng2-charts version 2.3.0
I don't use moment or chart.js in my project.
As I understand it, ng2-charts depends on chart.js and chart.js imports moment
If it helps my dependencies versions are:
I went ahead and did some more digging today and I have to report the following. I hope something can give you a hint of what is going on.
npm install in my Angular project, I notice that in node_modules/@types/chart.js/ a node_modules directory inside of which the moment should be, is not created for some reason. The same issue also appears if you run npm install chart.js --save explicitly. TL;DR moment depency is not installed.npm install if I open node_modules/@types/chart.js/package.json I notice that bundleDependencies is set to false but in the NPM documentation says that this needs to be an array.moment dependency in package.json, I see that the version is "moment": "^2.10.2" and not 2.25.1 as @KentarouTakeda says.node_modules/moment in the node_modules/@types/chart.js/ directory everything works. The final structure would be node_modules/@types/chart.js/node_modules/moment.Waiting on your help. Thank you in advance
Today my app magically worked. I did some digging around my node_modules directory and it seems that moment updated itself to 2.25.1
So @KentarouTakeda message seems to be correct.
The problem for me was that I didn't and I don't use moment anywhere so the dependency gets install by some other dependency of mine and I couldn't be sure if it was chart.js or another dependency.
Anyway, but to normal. Thank you again @lekoaf and @KentarouTakeda
Most helpful comment
This issue is a moment=2.25.0 bug. It seems to be fixed in 2.25.1.
https://github.com/moment/moment/pull/5487#issuecomment-622492292