nextcloud-libraries / webpack-vue-config

This is a base webpack configuration to use with Nextcloud apps https://npmjs.org/@nextcloud/webpack-vue-config
GNU Affero General Public License v3.0
8 stars 3 forks source link

fix: ignore `./locale` import from `moment/min/moment-with-locales` #533

Closed ShGKme closed 7 months ago

ShGKme commented 8 months ago

Fixes compatibility between @nextcloud/webpack-vue-config and @nextcloud/moment@1.3.0 (since migration to Vite).

@nextcloud/moment uses moment/min/moment-with-locales.js, which works only in Node.js and is not compatible with Webpack bundling. It has an unused function localLocale that requires locales by invalid relative path ./locale. Though it is not used, Webpack tries to resolve it with require.context and fails.

Example of issue in Talk, same in Text and other apps:

WARNING in ./spreed/node_modules/moment/min/moment-with-locales.js 2159:16-50
Module not found: Error: Can't resolve './locale' in '<...>\talk-desktop\spreed\node_modules\moment\min'

See also:

ShGKme commented 8 months ago

A fix on @nextcloud/moment side could be better, cc @susnux if you have any ideas.

susnux commented 8 months ago

How would you fix it? The problem is that we otherwise need to import every local in @nextcloud/moment manually.

ShGKme commented 8 months ago

How would you fix it? The problem is that we otherwise need to import every local in @nextcloud/moment manually.

I dunno, that is why I mentioned you =D

I didn't dig much into what happens in @nextcloud/moment and what/why was changed during the migration to Vite. The source issue is in the moment itself. That require is not correct in the moment's source, and it is so a classic issue that Webpack docs show the fix as an example of the IgnorePlugin usage. So we can fix it on the Webpack config side, but the fix on @nextcloud/moment seems less breaking.

Probably, import.glob in Vite + manual locales registration may work.

Anyway, I'm fine with merging this PR to fix the problem as well.

susnux commented 8 months ago

Probably, import.glob in Vite + manual locales registration may work.

This does only work with local imports not with modules :no_mouth: