Loading dayjs locale on demand with Vite
- Dominant language
- JavaScript
- Stars
- 48.7k
- Forks
- 2.5k
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
```js
import dayjs from 'dayjs';
const locales = ['en', 'es', 'pt'];
const modules = import.meta.glob('../node_modules/dayjs/locale/*.js', {
eager: true
});
locales.map(locale => {
modules[`../node_modules/dayjs/locale/${locale}.js`];
});
```
I get this in the console:
```bash
caught TypeError: Cannot read properties of undefined (reading 'locale')
at af.js?v=6d3900b8:1:1117
at af.js?v=6d3900b8:1:232
at af.js?v=6d3900b8:1:243
(
```
With:
```js
const modules = import.meta.glob('../node_modules/dayjs/locale/*.js', {
import: 'locale',
eager: true
});
```
I get this in the console:
```bash
caught SyntaxError: The requested module '/_nuxt/node_modules/dayjs/locale/af.js?v=6d3900b8' does not provide an export named 'locale'
```
**Expected behavior**
While the second error is expected, because the file export as default, the first one is unexpected and should import correctly, without error.
**Information**
- Day.js Version 1.11.7
- Ubuntu 22.04.2 LTS
- Chrome Version 112.0.5615.165
Contributor guide
Assessment
This issue has not been assessed yet.