react-intl-po icon indicating copy to clipboard operation
react-intl-po copied to clipboard

Running command as a npm script fails

Open vlad-nica opened this issue 8 years ago • 5 comments
trafficstars

So I bumped into the following issue: running rip json2pot 'i18n/messages/**/*.json' -o ./i18n/template.pot in the console works properly, whilst putting the command in package.json as a script and running it like npm run i18n-extract, generates an empty .pot file.

"scripts": {
    "i18n-extract": "rip json2pot 'i18n/messages/**/*.json' -o ./i18n/template.pot"
}

Thanks!

vlad-nica avatar Apr 25 '17 11:04 vlad-nica

I have no idea how it happened. Could you provide your project so I can reproduce? Or, you could take a look at this standalone repository for the settings.

evenchange4 avatar Apr 26 '17 12:04 evenchange4

Sorry for the late response but at least I'm coming back with a solution...the problem were the single quotes. If you run the command like rip json2pot 'i18n/messages/**/*.json' -o 'i18n/template.pot' the command crashes: Error: ENOENT: no such file or directory, open 'C:\Playground\react-intl-po-example\'output\messages.json''. (yes, I know ... windows). If you run it in console with quotes only for the first argument, everything works well. Same if you run it without any quotes at all. Now for npm script, it doesn't work. Why? I have no clue. But having no quotes in the command (on windows), will make things work in both console and npm scripts.

Sorry for the false alarm 😊

vlad-nica avatar May 02 '17 13:05 vlad-nica

But having no quotes in the command (on windows), will make things work in both console and npm scripts.

I think you already find a solution. I am not familiar with Windows' command. Maybe the document can be improved more Windows-friendly. Close it for now. Any further PRs are always welcome. 👌🏻

evenchange4 avatar May 05 '17 01:05 evenchange4

Got the same problem on Windows 8.1.

$ npm -v
5.6.0
$ node -v
v8.11.1

Script doesn't work from npm run but does work from cmd. Problem definitely relates to current path.

{
  "scripts": {
    "json2pot": "rip json2pot './build/messages/**/*.json' -o ./src/locales/translations.pot",
    "po2json": "rip po2json './src/locales/he.po' -m './build/messages/**/*.json' -o ./src/locales/translations.json"
  }
}

So

npm run json2pot
npm run po2json

produces empty files. Meantime in command line

$ node_modules/.bin/react-intl-po json2pot './build/messages/**/*.json' -o ./src/locales/translations.pot
$ node_modules/.bin/react-intl-po po2json './src/locales/he.po' -m './build/messages/**/*.json' -o ./src/locales/translations.json

works perfect.

ybelenko avatar Mar 30 '18 12:03 ybelenko

Same problem in macos, the pot file is generated empty. Regardless of run via yarn script or directly.

samkelleher avatar Jan 08 '20 12:01 samkelleher