Importing moment into TypeScript project

前端 未结 2 541
说谎
说谎 2020-12-20 12:02

I am trying to use moment in my TypeScript project but when I use the line,

import moment from \'moment\';

I get the error:

相关标签:
2条回答
  • 2020-12-20 12:58

    The correct syntax is:

    import * as moment from 'moment';
    
    0 讨论(0)
  • 2020-12-20 13:01

    I had the same issue and solved the problem in my project by adding allowSyntheticDefaultImports: true in compilerOptions in my tsconfig.json file and then I used the syntax

    import moment from 'moment';
    

    Reference: "https://momentjs.com/docs/#/use-it/typescript/"

    0 讨论(0)
提交回复
热议问题