Parcel: 馃檵 moment.js zh-cn fail

Created on 4 Jan 2018  路  6Comments  路  Source: parcel-bundler/parcel

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

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

tim 20180104180226

Bug Waiting

Most helpful comment

@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 :
    ```js
    import locale from 'moment/src/locale/zh-cn'

moment.locale('zh-cn', locale)
```

  • Use the CommonJS moment :
    js import moment from 'moment/moment'

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

All 6 comments

What is the error that parcel throws? Or none?

I do have a similar issue. Parcel works fine, but the second import does not do what it should.
It is supposed to modify the moment global variable to add stuff into it, but I guess it cannot access moment as it's not global?

check pr #530 and see if it works.

@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 :
    ```js
    import locale from 'moment/src/locale/zh-cn'

moment.locale('zh-cn', locale)
```

  • Use the CommonJS moment :
    js import moment from 'moment/moment'

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

in my case, this is what fix it:

import * as moment from 'moment/moment';
import 'moment/locale/fr';

Should have been fixed

Was this page helpful?
0 / 5 - 0 ratings

Related issues

termhn picture termhn  路  3Comments

dotdash picture dotdash  路  3Comments

Niggler picture Niggler  路  3Comments

donaldallen picture donaldallen  路  3Comments

jzimmek picture jzimmek  路  3Comments