When working with TypeScript and trying to utilize "moment-duration-format", I encountered an issue where webpack is constantly throwing errors stating that it cannot locate the "format" method in this line of code:
return moment.duration(value, "minutes").format("...");
Here are the dependencies listed in package.json:
{
"devDependencies": {
"@types/moment-duration-format": "^1.3.7"
},
"dependencies": {
"moment": "^2.18.1",
"moment-duration-format": "^1.3.0"
}
}
And here is tsconfig.json configuration provided:
{
"compilerOptions": {
"typeRoots": [ "./node_modules/@types" ]
}
}
Within the Angular2 component:
import * as moment from "moment";
import * as momentDurationFormat from "moment-duration-format";
...
let result: string = moment.duration(this.selectedHangarDistance * 10, "minutes").format("...")
I even attempted using:
import "moment-duration-format";
However, the error persists:
ERROR in [at-loader] ./src/app/components/building/shop/shop.component.ts:190:81 TS2339: Property 'format' does not exist on type 'Duration'.