fix: message compiler tries to parse node_module dependency
Reporting a bug?
Using @intlify/unplugin-vue-i18n and having html-to-text on a Nuxt page, as given in the reproduction codesandbox, yields an error. Diving deeper reveals that a source file is tried to be loaded, which does not contain translations, but special characters. It ends in:
...
♣
♣
:
∷
⩴
≔
≔
,
@
To me this looks very much like coming from https://yarnpkg.com/package/entities or similar.
Expected behavior
The bundler only tries to compile actual translations, not special characters that seem to come out of node_modules.
Reproduction
Run a yarn build over here: https://codesandbox.io/s/i18n-html-to-text-urt22w?file=/pages/index.vue
Try commenting the htmlToText usage out and the basic string usage in and see that the error vanishes.
Note: the error message there is obfuscated due to https://github.com/intlify/vue-i18n-next/issues/1142.
Issue Package
unplugin-vue-i18n
System Info
System:
OS: Linux 5.13 Debian GNU/Linux 10 (buster) 10 (buster)
CPU: (8) x64 Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz
Memory: 43.03 GB / 62.60 GB
Container: Yes
Shell: 5.0.3 - /bin/bash
Binaries:
Node: 16.15.1 - ~/.nvm/versions/node/v16.15.1/bin/node
Yarn: 1.22.19 - ~/.nvm/versions/node/v16.15.1/bin/yarn
npm: 8.11.0 - ~/.nvm/versions/node/v16.15.1/bin/npm
npmPackages:
vue: 3.2.37 => 3.2.37
vue-i18n: 9.2.2 => 9.2.2
Screenshot
No response
Additional context
Maybe the node_modules folder can be ignored?
Validations
- [X] Read the Contributing Guidelines.
- [X] Read the README
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Check that this is a concrete bug. For Q&A open a GitHub Discussion.
My suggestion for a fix is to set the include option's default to exclude node_modules.
A workaround is to set the default yourself:
vite: {
plugins: [
VueI18nPlugin({
include: '!' + resolve(dirname(fileURLToPath(import.meta.url)), './node_modules/**'),
}),
],
},
It'd take me some time to figure out how to implement that default. If you think my suggestion above is fine, @kazupon, it'd be great if you could implement it! :partying_face: Otherwise just tell that this is open for grabs and whoever gets time to work on it first, does so :)
A workaround would be to just set the include option to include all source files, e.g.
vite: {
plugins: [
VueI18nPlugin({
include: resolve(dirname(fileURLToPath(import.meta.url)), './locales/**'),
}),
],
},
I think It would be nice to support an exclude option, like rollup's @rollup/json plugin.
https://github.com/rollup/plugins/tree/master/packages/json#exclude
If we don’t specify it, it would be nice to exclude the default node_modules.
I think this issue is fixed with #195 Thanks!