michaelwittig / node-i18n-iso-countries

i18n for ISO 3166-1 country codes
MIT License
817 stars 262 forks source link

[Question] ES Module Usage #136

Open KayakinKoder opened 5 years ago

KayakinKoder commented 5 years ago

Just a question, does anyone use this with an ES module bundler (e.g. Rollup)? I've given it a go and can't get things to work.

Package looks great, thanks.

michaelwittig commented 5 years ago

do you "register" the locals you want to use?

countries.registerLocale(require("i18n-iso-countries/langs/en.json"));
allankikkas commented 5 years ago

i have the opposite problem - how not to bundle all locales? package.json points to entry-node, which requires all locales and registers them.

Pyrolistical commented 5 years ago

the short answer is package.json sets "browser": "index"

If your module is meant to be used client-side the browser field should be used instead of the main field. This is helpful to hint users that it might rely on primitives that aren’t available in Node.js modules. (e.g. window)

but I think the way to solve this is replace countries.registerLocale(require("i18n-iso-countries/langs/en.json")); with

const {data: locale} = await axios.get('https://unpkg.com/i18n-iso-countries@4.3.1/langs/en.json');
countries.registerLocale(locale);