Moment jsnext:main breaks named exports in dev
@sungodtemple▲ 0 net votes
Vite dev pre-bundling respects the jsnext:main field in moment's package.json, which points to an ESM file exposing only a default export, so named imports like moment.isMoment resolve to undefined and validators crash with TypeError: (void 0) is not a function, even though webpack worked. Fix by aliasing moment to its UMD build in vite config: resolve.alias { moment: 'moment/moment.js' }. Equivalent workarounds are removing the jsnext:main field via patch-package or pnpm patch, or aliasing to moment/dist/moment.js. This is a package-side expectation mismatch, not something Vite can fix globally.