Search code examples
angular9moment-timezoneangular10

Moment Timezone in Angular 9


Currently, I upgrade my Angular project form 8 to 9.
The project's using a "@types/moment-timezone": "^0.5.30" in package.json
Now this package has been deprecated. https://www.npmjs.com/package/@types/moment-timezone

When I run the project ng serve, it shows up this error message

user.model.ts:3:25 - error TS7016: Could not find a declaration file for module 'moment-timezone'. '/home/bunthai/sftp/upgrade/projectg/ui/ctr/node_modules/moment-timezone/index.js' implicitly has an 'any' type.
  Try `npm install @types/moment-timezone` if it exists or add a new declaration (.d.ts) file containing `declare module 'moment-timezone';`

import * as moment from 'moment-timezone';
                          ~~~~~~~~~~~~~~~~~

How to deal with this problem?


Solution

  • I've found the solution: https://stackoverflow.com/a/42505940/10258377

    In my case change from import * as moment from 'moment-timezone' to const moment = require('moment-timezone');