简体   繁体   中英

Momentjs in Polymer WebComponent - global is undefined

I want to use momentjs in a webcomponent for a custom card in home-assistant

When I try to import the library, I get the following error:

Cannot set property 'moment' of undefined

import './lib/moment.min.js';

class ContentCardExample extends HTMLElement {
    ...
}

Any idea what is going on?

If you installed moment from npm, you should import it as:

import moment from 'moment/src/moment.js';

and include any locales like this (in case you need them:

import 'moment/src/locale/es.js';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM