question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

🙋 moment.js zh-cn fail

See original GitHub issue

Using the following code to do the Sinization of the time, it is failed by parcel. But by webpack,it is ok. Can you help me?

import  moment from 'moment';
import 'moment/locale/zh-cn'
moment.locale('zh-cn');

tim 20180104180226

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
fathybcommented, Jan 17, 2018

@PlayMa256 it shouldn’t work on this case.

The problem :

  • import moment from 'moment' is resolved to an ES6 module, according to the module package.json field
  • import 'moment/locale/zh-cn' is resolved to an UMD module, which uses the moment commonjs module

What it means : you are using ES6 moment, the locale uses CommonJS moment, it’s two different instances, so the locale will not apply.

Workaround (pick one) :

  • Use the ES6 locale :
    import locale from 'moment/src/locale/zh-cn'
    
    moment.locale('zh-cn', locale)
    
  • Use the CommonJS moment :
    import moment from 'moment/moment'
    

Caused by #299 (follow up #359), related to #418

3reactions
matheus1lvacommented, Jan 5, 2018

What is the error that parcel throws? Or none?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Guides - Moment.js
The guides area is designed to help developers learn to better interact with the date and time problem domain, and the Moment.js library....
Read more >
How to set language globally for moment.js - Stack Overflow
You can change moment locale globally like that: import moment from 'moment'; import localization from 'moment/locale/fr'; moment.locale('fr', localization);.
Read more >
⚓ T123080 Moment.js does not support all Chinese ...
This will cause modules depending on momentjs to display English fallback if the interface language for the user is zh-Hans, for example. Details....
Read more >
MomentJS - Quick Guide - Tutorialspoint
Moment JS allows displaying of date as per localization and in human readable format. You can use MomentJS inside a browser using the...
Read more >
Javacript 3.23 bug with momentjs package? - Esri Community
It seems that the extra .js on moment in init.js is crapping things out and I notice that this has changed in JS...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found