Spittal / vue-i18n-extract

Manage vue-i18n localization with static analysis
https://pixari.github.io/vue-i18n-extract/#what-is-it
MIT License
313 stars 86 forks source link

Not working with es6 modules #142

Closed theunclehonnor closed 2 years ago

theunclehonnor commented 3 years ago

Hello, i`m trying to setup vue-i18n-extract for my project. My translations are stored in js files (es6 modules) and i catch an error:

artem@art-computer:~/project/vue-i18n-extract-esm-example$ yarn run vue-i18n-extract use-config
yarn run v1.22.11
$ /home/artem/project/vue-i18n-extract-esm-example/node_modules/.bin/vue-i18n-extract use-config

Using config file found at /home/artem/project/vue-i18n-extract-esm-example/vue-i18n-extract.config.js
[vue-i18n-extract] SyntaxError: Unexpected token 'export'
    at /home/artem/project/vue-i18n-extract-esm-example/node_modules/vue-i18n-extract/dist/vue-i18n-extract.umd.js:184:47
    at Array.map (<anonymous>)
    at readLanguageFiles (/home/artem/project/vue-i18n-extract-esm-example/node_modules/vue-i18n-extract/dist/vue-i18n-extract.umd.js:172:24)
    at createI18NReport (/home/artem/project/vue-i18n-extract-esm-example/node_modules/vue-i18n-extract/dist/vue-i18n-extract.umd.js:322:27)
    at CAC.<anonymous> (/home/artem/project/vue-i18n-extract-esm-example/node_modules/vue-i18n-extract/bin/vue-i18n-extract.js:39:5)
    at CAC.runMatchedCommand (/home/artem/project/vue-i18n-extract-esm-example/node_modules/cac/dist/index.js:611:34)
    at CAC.parse (/home/artem/project/vue-i18n-extract-esm-example/node_modules/cac/dist/index.js:538:12)
    at Object.<anonymous> (/home/artem/project/vue-i18n-extract-esm-example/node_modules/vue-i18n-extract/bin/vue-i18n-extract.js:48:5)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)

Steps to reproduce:

  1. Clone: https://github.com/theunclehonnor/vue-i18n-extract-esm-reproduce
  2. yarn i18n-check or yarn run vue-i18n-extract use-config

Are es6 modules supported?

DFJacobsen commented 3 years ago

Same problem here. As this issue is 2+ months old, are there any plans to fix this?

Spittal commented 3 years ago

Hey sorry about this. Both contributors here are full time programmers with families and admittedly don't have a tonne of time to spend solving every issue.

I have some time scheduled over the holidays to do some open source stuff, where I will take a look at this. Otherwise we're 100% open to PRs.

DFJacobsen commented 3 years ago

Hey sorry about this. Both contributors here are full time programmers with families and admittedly don't have a tonne of time to spend solving every issue.

I have some time scheduled over the holidays to do some open source stuff, where I will take a look at this. Otherwise we're 100% open to PRs.

Absolutely understandable :)

Spittal commented 2 years ago

Hi friends if you end the file in .mjs as opposed to .js it will work! This has to do with node, not vue-i18n-extract. You can see an explanation of this here: https://nodejs.medium.com/announcing-a-new-experimental-modules-1be8d2d6c2ff

saxoncameron commented 1 year ago

Hey @Spittal I'm having this same issue, I think! I recently had to change my repo package.json to type: module to facilitate some dependency upgrades, and this broke my i18n linting npm script due to it being in CJS.

I tried amending the file to *.cjs, but the config cannot be found; I tried converting it to ESM and changing the file to *.mjs but the config cannot be found, no matter what combo I do it seems like the vue-i18n-extract report command cannot find my config file which is named as standard.

I feel like maybe this would be solved if I could explicitly specify the path to the config file? But AFAIK you can't do that on the CLI. Any suggestions...?

saxoncameron commented 1 year ago

I found a hacky fix for this locally with using patch-package:

mreduar commented 6 months ago

I found a hacky fix for this locally with using patch-package:

  • Follow setup instructions in patch-package docs
  • Rename config file to vue-i18n-extract.config.cjs
  • Edit package file node_modules/vue-i18n-extract/dist/vue-i18n-extract.umd.js ~L57 pathToConfigFile from .js to .cjs
  • Run npx patch-package vue-i18n-extract

FANTASTIC!!! Thank you so much for this. It would take me a few hours to find a solution like this.