Dynamic import via cdn url - exports is not defined #2795
Replies: 5 comments 9 replies
-
I think you want |
Beta Was this translation helpful? Give feedback.
-
Am trying to use
|
Beta Was this translation helpful? Give feedback.
-
@arvindanta You were almost there. Here are two ways to load esm locales at runtime from that specific CDN: const frCA = (await import(`https://cdn.jsdelivr.net/npm/date-fns/esm/locale/fr-CA/index.js`)).default;
console.log(frCA.code); // fr-CA
const { default: enCA } = await import(`https://cdn.jsdelivr.net/npm/date-fns/esm/locale/en-CA/index.js`);
console.log(enCA.code); // en-CA |
Beta Was this translation helpful? Give feedback.
-
@fturmel Do you know if there is a way where I can pull the locale modules as json files instead of js files ?. |
Beta Was this translation helpful? Give feedback.
-
@fturmel the dynamic import using |
Beta Was this translation helpful? Give feedback.
-
Hi Team,
Am trying to dynamically import locale modules via the cdn url.
await import(
https://cdn.jsdelivr.net/npm/date-fns/locale/${locale}/index.js
)
Am getting
exports is not defined
error.Can you please provide a way to import locale modules dynamically in the browser via dynamic import.?
Beta Was this translation helpful? Give feedback.
All reactions