urish/ngx-moment

Angular 13 + ngx-moment 6.0.2: This module is declared with using 'export =

vadimwe opened this issue ยท 9 comments

Multiple error in CLI:
This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.

Problem goes away if allowSyntheticDefaultImports: true in tsconfig.json

Did you search for duplicate issue? [Yes / No]
Yes

Please describe the issue and steps to reproduce, preferably with a code sample / plunker:

Angular update till v13.*
Ionic update till 6.*
ngx-moment update to 6.0.2
ionic serve/build

  • Angular version? 13
  • TypeScript version? 4.5.4
  • moment version? 2.29.1
  • Are you using moment-timezone? No
  • Are you using the angular-cli? Yes
  • Using Rollup/Webpack/System.js/Ionic/similar? Yes, Ionic

I also faced the same issue with 6.0.2. I think the import statement has been changed to 'import 'moment' from moment;'. Should it be 'import * as moment from 'moment';'? I saw this change while trying between 6.0.1 and 6.0.2.

@vadimwe, Meanwhile, I would advise to switch to 6.0.1 and then try to build the solution.

Back porting to 6.0.1 re-introduces this issue #245

Enable the allowSyntheticDefaultImports in tsconfig bypass this issue, not sure if the maintainer have to "fix" anything. Maybe for backward compatibility ?

If the maintainer changes import moment from 'moment'; back to import * as moment from 'moment'; then the allowSyntheticDefaultImports flag would not need to be set to true in your tsconfig of the project using the dependency.

Will @JaxonWright change ever be implemented?

+1

I am sure you guys wont like my comment as it might not be helpful however i was in your place once. I got rid of moment library all together and moved to date-fns - its much lighter and more robust. Moment was quite good in the early days but now it was getting harder to maintain with changing NG versions.

Following @hassanasad's advice is indeed the correct one, as the moment team has announced they deprecated the project.

We recognize that many existing projects may continue to use Moment, but we would like to discourage Moment from being used in new projects going forward. Instead, we would like to recommend alternatives that are excellent choices for use in modern applications today.