Skip to content

Get cryptic error Cannot read properties of undefined (reading 'message') for a simple problem #375

@Sinc63

Description

@Sinc63

Reporting a bug?

I am updating i18n translations for our project. After running 17 translations for French I started getting an error from the i18n plugin, with none of the stack trace leading back to my code line, just the file name.

Cannot read properties of undefined (reading 'message')
5:56:50 PM [vite] Internal server error: Cannot read properties of undefined (reading 'message')
  Plugin: vite-plugin-vue-i18n
  File: /var/src/project/src/i18n/fr.json
      at newOptions.onError (/var/src/project/node_modules/@intlify/bundle-utils/lib/codegen.js:102:48)
      at newOptions.onError (/var/src/project/node_modules/@intlify/bundle-utils/lib/codegen.js:102:36)
      at newOptions.onError (/var/src/project/node_modules/@intlify/bundle-utils/lib/codegen.js:102:36)
      at emitError (/var/src/project/node_modules/@intlify/message-compiler/dist/message-compiler.cjs.js:197:13)
      at readTokenInPlaceholder (/var/src/project/node_modules/@intlify/message-compiler/dist/message-compiler.cjs.js:681:21)
      at readToken (/var/src/project/node_modules/@intlify/message-compiler/dist/message-compiler.cjs.js:776:20)
      at Object.nextToken (/var/src/project/node_modules/@intlify/message-compiler/dist/message-compiler.cjs.js:823:16)
      at parseNamed (/var/src/project/node_modules/@intlify/message-compiler/dist/message-compiler.cjs.js:910:19)
      at parseMessage (/var/src/project/node_modules/@intlify/message-compiler/dist/message-compiler.cjs.js:1048:37)
      at parseResource (/var/src/project/node_modules/@intlify/message-compiler/dist/message-compiler.cjs.js:1096:25)

The simple problem is that other tools got an invalid translation back. I use I18NAlly to fetch translations (I think from Google), and in this one case:
"from-users-usernames": "from users {usernames}",
became
"from-users-usernames": "des utilisateurs {nom d'utilisateurs}",

It would be very helpful, given that I've seen Google translate parameter names in other cases, if intlify would explicitly detect problems that it can't handle in the parameter name (whether that's the space or the apostrophe or both), and report an explicit error, something like invalid parameter name in translation string "from-users-usernames" in /var/src/project/src/i18n/fr.json:1282. Note that I gave both the tag and the line number, but either would likely be sufficient.

Expected behavior

If a parameter name isn't acceptable an explicit warning should be given, specifying at the very least that a specific string or line number has a problem with the parameter name. Specifying the limitations of the parameter names in the error might be help, if not too cumbersome,. A link to docs might be sufficient. (And note that it's not the case that I expect the tool to support a two word parameter name, I just need it to explicitly detect the problem since the translators sometimes do that to us.)

Reproduction

See my sample and insert it in your favourite app to test.

Issue Package

vite-plugin-vue-i18n

System Info

Need to install the following packages:
  envinfo@7.13.0

"@intlify/vite-plugin-vue-i18n@^3.3.1":
"@intlify/message-compiler@9.2.2",
vue-i18n@^9.2.0-beta.35:

Screenshot

No response

Additional context

No response

Validations

  • Read the Contributing Guidelines.
  • Read the README
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A open a GitHub Discussion.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions