0

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?

Spring
  • 831
  • 1
  • 12
  • 42

2 Answers2

1

You need to remove this import, and import your wanted timezone manualy eg:

import moment from "moment";
import "moment/locale/fr";
moment.locale('fr')

If you don't import another timezone, you'll get the default nodeJS server timezone. If you want another, you need to import it and use it.

Just and advice, stop using this library if you can.

lovis91
  • 1,988
  • 2
  • 14
  • 24
1

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');

Spring
  • 831
  • 1
  • 12
  • 42