i18n-unused: Fails with error with "mark" and "remove"

It’s working fine (and giving seemingly correct results) with “display-unused”. However, when I run “mark-unused” or “remove-unused”, I get an error like so:

 Successfully marked: /Users/carl/GitHub/opensupply/client/packages/common/src/intl/locales/ar/app.json
(node:18673) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'admin' of undefined
    at /Users/carl/GitHub/opensupply/client/node_modules/i18n-unused/dist/i18n-unused.cjs:469:51
    at /Users/carl/GitHub/opensupply/client/node_modules/i18n-unused/dist/i18n-unused.cjs:384:7
    at Array.reduce (<anonymous>)
    at applyToFlatKey (/Users/carl/GitHub/opensupply/client/node_modules/i18n-unused/dist/i18n-unused.cjs:382:16)
    at /Users/carl/GitHub/opensupply/client/node_modules/i18n-unused/dist/i18n-unused.cjs:468:37
    at Array.forEach (<anonymous>)
    at /Users/carl/GitHub/opensupply/client/node_modules/i18n-unused/dist/i18n-unused.cjs:468:22
    at Array.forEach (<anonymous>)
    at markUnusedTranslations (/Users/carl/GitHub/opensupply/client/node_modules/i18n-unused/dist/i18n-unused.cjs:465:35)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:18673) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:18673) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

It deals with the first file (app.json) fine, but then gets no further.

Any ideas?

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (10 by maintainers)

Most upvoted comments

Thx, I made note about line break.

@CarlosNZ, I think I found the problem =) I looked at your update commit, you update package version, but not turn on flat json option in config, please, add follow option (it’s in nested mode by default):

Ah right, yes, my bad – I didn’t realise we needed to manually add that config option. Working well now, thank you 😃

I’ll close this issue now, but I just wanted to point out one tiny little thing you might want to address at some point: When running mark or remove your script removes a final line break in each file (even when there’s nothing changed), which is different to how our auto-formatter (Prettier) does it (adds a final line break). So any file that we’ve manually saved shows up in the git diff after running this script, even if nothing has actually changed. Screen Shot 2022-04-06 at 9 06 53 AM

The current tests do not cover the codebase. I’ll deal with this issue later. I’ll try run clean installation on another machine later.

@CarlosNZ, it’s strange, because I cloned your repo and ran in i18n-unused branch:

Screenshot 2022-04-04 at 18 05 47

Try remove your node_modules or clear cache and install packages again.

Ok, I’ll take a look this week.