Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
347 views
in Technique[技术] by (71.8m points)

javascript - Importing moment into TypeScript project

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

import moment from 'moment';

I get the error:

'node_modules/moment/moment' has no default export.

I have also tried,

import moment from 'moment/src/moment';

but then I get the error:

'Cannot find module moment/src/moment'.

Does anybody know a way of doing this? Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The correct syntax is:

import * as moment from 'moment';

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...