Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.0.5: [vue-i18n-extract] Error: vueFiles glob has no files. #159

Closed
Cyclodex opened this issue Apr 28, 2022 · 19 comments · Fixed by #166
Closed

2.0.5: [vue-i18n-extract] Error: vueFiles glob has no files. #159

Cyclodex opened this issue Apr 28, 2022 · 19 comments · Fixed by #166

Comments

@Cyclodex
Copy link

Cyclodex commented Apr 28, 2022

Since today, my npm run script is not working anymore, it throws a error about vueFiles glob has no files..

I see there was a release 2.0.5 yesterday.
2.0.4 works perfectly fine.

My config file has:
vueFiles: "./src/**/*.?(ts|js|vue)",

Did you change something on the files matcher since 2.0.4?

image

My workaround for now is, to execute your 2.0.4 version:
"i18n:reportDeOnly": "npx [email protected] --languageFiles ./src/locales/de-CH.json",

@Spittal
Copy link
Owner

Spittal commented Apr 28, 2022

I didn't specifically, but I did update the glob package which might have changed the syntax?

@frynt
Copy link

frynt commented May 11, 2022

Same problem with 2.0.5 and 2.0.6 version, even with a vue-i18n-extract.config.js file.

2.0.4 works but doesnt make the job for me because it doesnt recognize the --exclude parameter. (is it a bug too ?)

@mreduar
Copy link

mreduar commented May 12, 2022

Same problem here

@hk67393309
Copy link

hk67393309 commented May 14, 2022

Since today, my npm run script is not working anymore, it throws a error about vueFiles glob has no files..

I see there was a release 2.0.5 yesterday. 2.0.4 works perfectly fine.

My config file has: vueFiles: "./src/**/*.?(ts|js|vue)",

Did you change something on the files matcher since 2.0.4?

image

My workaround for now is, to execute your 2.0.4 version: "i18n:reportDeOnly": "npx [email protected] --languageFiles ./src/locales/de-CH.json",

2.0.4 use glob ^7.1.6, 2.0.6 use glob ^8.0.1, and then Error: vueFiles glob has no files.
Please rollback glob to ^7.1.6, otherwise fix the bug.

@hk67393309
Copy link

hk67393309 commented May 14, 2022

but use glob alone work fine.

image

@kleinfreund
Copy link
Contributor

kleinfreund commented May 18, 2022

I think I have a theory that explains these issues.

The call to glob.sync(src):

const targetFiles = glob.sync(src);

receives the result of path.resolve(process.cwd(), vueFilesGlob):

const vueFiles = readVueFiles(path.resolve(process.cwd(), vueFilesGlob));

where vueFilesGlob is something like "./src/**/*.?(js|vue)". Combined, the call is effectively something like this:

require('glob').sync(
  require('path').resolve(process.cwd(), "./src/**/*.?(js|vue)")
)

According to node-glob: changelog.md: 8.0:

Glob pattern paths must use forward-slashes as path separators, since \ is an escape character to match literal glob pattern characters.

On Windows, the following will result in a string containing two backslashes as path separators (i.e. \\ instead of /):

require('path').resolve(process.cwd(), "./src/**/*.?(js|vue)")

A naive fix for this could be to add something like .replace(/\\/g, '/') to the path before passing it to glob.sync.

I’m happy to file a pull request for this if that is indeed the case.

@mreduar
Copy link

mreduar commented May 27, 2022

I am sorry to say that this problem has not yet been solved on Windows with the latest version 2.0.7. Only works from npx command

@kleinfreund
Copy link
Contributor

I am sorry to say that this problem has not yet been solved on Windows with the latest version 2.0.7.

@mreduar What’s the issue that’s occurring for you? Do you get any error messages?

@mreduar
Copy link

mreduar commented May 27, 2022

@mreduar What’s the issue that’s occurring for you? Do you get any error messages?

Yes, the error message is as follows.

> vue-i18n-extract report --vueFiles './resources/js/**/*.vue' --languageFiles './lang/js/*.json' --add --remove --noEmptyTranslation=*

[vue-i18n-extract] Error: vueFiles glob has no files.
    at readVueFiles (C:\Users\Eduar\Projects\my_project\node_modules\vue-i18n-extract\dist\vue-i18n-extract.umd.js:83:13)
    at createI18NReport (C:\Users\Eduar\Projects\my_project\node_modules\vue-i18n-extract\dist\vue-i18n-extract.umd.js:338:22)
    at CAC.<anonymous> (C:\Users\Eduar\Projects\my_project\node_modules\vue-i18n-extract\bin\vue-i18n-extract.js:47:5)
    at CAC.runMatchedCommand (C:\Users\Eduar\Projects\my_project\node_modules\cac\dist\index.js:614:34)
    at CAC.parse (C:\Users\Eduar\Projects\my_project\node_modules\cac\dist\index.js:541:12)
    at Object.<anonymous> (C:\Users\Eduar\Projects\my_project\node_modules\vue-i18n-extract\bin\vue-i18n-extract.js:56:5)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)

It should be noted that I have to use this command, because if I use it the way the readme example (with *.?(js|vue) and *.?(json|yml|yaml|js)) says it doesn't work either.
"vue)'" is not recognized as an internal or external command. is the error if I use it with the regular expression in that way.

Edit:

I have downloaded the repository and performed some tests.
I've placed a console.log on dist\vue-i18n-extract.umd.js:74 to see if the path is correct and if glob.sync(normalizedSrc); is returning the file correctly.

I have done the test with only one file, placing only that file with the relative path, so I modified the script in package.json and now it looks like this:
"demo": "node ./bin/vue-i18n-extract.js report --vueFiles ./tests/fixtures/vue-files/Basic.vue --languageFiles './tests/fixtures/lang/**/*.?(json)'",

And the error remains the same.

➜ npm run demo

> [email protected] demo
> node ./bin/vue-i18n-extract.js report --vueFiles ./tests/fixtures/vue-files/Basic.vue --languageFiles './tests/fixtures/lang/**/*.?(json)'

➜➜➜ console.log(src, targetFiles); C:\Users\Eduar\Projects\vue-i18n-extract\tests\fixtures\vue-files\Basic.vue [] 
[vue-i18n-extract] Error: vueFiles glob has no files.
    at readVueFiles (C:\Users\Eduar\Projects\vue-i18n-extract\dist\vue-i18n-extract.umd.js:77:13)
    at createI18NReport (C:\Users\Eduar\Projects\vue-i18n-extract\dist\vue-i18n-extract.umd.js:326:22)
    at CAC.<anonymous> (C:\Users\Eduar\Projects\vue-i18n-extract\bin\vue-i18n-extract.js:47:5)
    at CAC.runMatchedCommand (C:\Users\Eduar\Projects\vue-i18n-extract\node_modules\cac\dist\index.js:614:34)
    at CAC.parse (C:\Users\Eduar\Projects\vue-i18n-extract\node_modules\cac\dist\index.js:541:12)
    at Object.<anonymous> (C:\Users\Eduar\Projects\vue-i18n-extract\bin\vue-i18n-extract.js:56:5)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)

I have checked that the path C:\Users\Eduar\Projects\vue-i18n-extract\tests\fixtures\vue-files\Basic.vue is correct, so it seems that the problem comes from glob.sync(normalizedSrc) Since it returns an empty array

@kleinfreund
Copy link
Contributor

@mreduar Hey there,

After dist/vue-i18n-extract.umd.js:73, can you add console.log({ src, normalizedSrc }) and run the following (the same command you used above):

node ./bin/vue-i18n-extract.js report --vueFiles ./tests/fixtures/vue-files/Basic.vue --languageFiles './tests/fixtures/lang/**/*.?(json)'

On my machine, the two paths logged are these (I use Ubuntu):

{
  src: '/home/phil/dev/packages/vue-i18n-extract/tests/fixtures/vue-files/Basic.vue',
  normalizedSrc: '/home/phil/dev/packages/vue-i18n-extract/tests/fixtures/vue-files/Basic.vue'
}

In your case, I would expect the two to look like this:

{
  src: 'C:\\Users\\Eduar\\Projects\\my_project\\node_modules\\vue-i18n-extract\\tests\\fixtures\\vue-files\\Basic.vue',
  normalizedSrc: 'C:/Users/Eduar/Projects/my_project/node_modules/vue-i18n-extract/tests/fixtures/vue-files/Basic.vue'
}

If that is indeed the result that you’re getting, can you please tell us which version of glob is installed in your project (i.e. check the version field in the node_modules/glob/package.json file). Mine is v8.0.3.

In case this doesn’t lead to any useful results, you can also try and perform like this some specific tests around the glob package by running node in a terminal and then import the package and running glob.sync manually like this:

const glob = require('glob')
glob.sync('C:/Users/Eduar/Projects/my_project/node_modules/vue-i18n-extract/tests/fixtures/vue-files/Basic.vue')

That should yield results.

@mreduar
Copy link

mreduar commented May 28, 2022

I suspected it from the beginning, but I wasn't sure since I have no experience with javascript packages. My suspicion was that the files inside dist folder were not updated with respect to the changes you made in PR #166, so normalizedSrc is not an existing variable in the dist/vue-i18n-extract.umd.js file. It's only available in src\create-report-vue-files.ts, so I did a compile with npm run build and now the files are updated and I don't get the error and the console prints the files correctly and this is the console.log output

{
  src: 'C:\\Users\\Eduar\\Projects\\vue-i18n-extract\\tests\\fixtures\\vue-files\\Basic.vue',
  normalizedSrc: 'C:/Users/Eduar/Projects/vue-i18n-extract/tests/fixtures/vue-files/Basic.vue',
  targetFiles: [
    'C:/Users/Eduar/Projects/vue-i18n-extract/tests/fixtures/vue-files/Basic.vue'
  ]
}

@kleinfreund
Copy link
Contributor

@mreduar Aha! That explains it. Yes, the files in the dist directory of the project have not been re-built. This should probably be done to simplify local development processes.

That means the fix is working for you then?

@mreduar
Copy link

mreduar commented May 28, 2022

@kleinfreund Yes, the solution in PR #166 works if I do the compilation in the package, however in the project I am using the package does not work as it needs to have the latest changes in dist I guess.
So it will be to send another PR with the compilation with the latest changes or have @Spittal do it.

@kleinfreund
Copy link
Contributor

@mreduar I filed another PR for addressing this: #170

@mreduar
Copy link

mreduar commented May 28, 2022

Thank you so much @kleinfreund!

@woncode
Copy link

woncode commented Aug 15, 2022

I also meet this error in version 2.0.7,I'm use windows 10.
my cmd is vue-i18n-extract report --vueFiles 'src/views/**/*.?(vue)' --languageFiles 'src/lang/zh.json'

I log the path as below
image

and find it become as below
image

so, fix this error need remove the quotation mark for vueFiles and languageFiles argument.

this cmd will work: vue-i18n-extract report --vueFiles src/views/**/*.?(vue) --languageFiles src/lang/zh.json

@diengv
Copy link

diengv commented Jun 5, 2023

my window 11: fix done
vue-i18n-extract report --noEmptyTranslation=\"*\" --add true --vueFiles=\"./src/**/*.?(vue|ts)\" --languageFiles=\"./src/locales/*.json\"

@dadyday
Copy link

dadyday commented Jan 22, 2024

Will not work on windows.
Please fix: src = src.replace(/\\/g, '/'); in readLanguageFiles(src) and readVueFiles(src)

@fatih-koc
Copy link

Please fix this issue. We are not able to define multiple folders or a single /src folders.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants