question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Failing to set `include` param causes all json imports to be parsed by i18n

See original GitHub issue

Reporting a bug?

I did not set the include config param since I don’t use any translation files and just use <i18n> blocks.

This caused vite-plugin-vue-i18n to parse all json imports as message files. Such that a regular json import threw the error seen below:

file: .../app/src/app_config.json
error during build:
TypeError: Cannot read property 'message' of undefined

Expected behavior

No files should be parsed for messages when include is not specified.

Reproduction

Tell me if needed

Issue Package

vite-plugin-vue-i18n

System Info

System:
    OS: Linux 5.3 Debian GNU/Linux 10 (buster) 10 (buster)
    CPU: (8) x64 Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz
    Memory: 7.96 GB / 15.41 GB
    Container: Yes
    Shell: 5.0.3 - /bin/bash
  Binaries:
    Node: 13.14.0 - /usr/bin/node
    npm: 6.14.4 - /usr/bin/npm
  Browsers:
    Chrome: dev
  npmPackages:
    @intlify/vite-plugin-vue-i18n: ^2.4.0 => 2.4.0 
    @intlify/vue-i18n-loader: ^1.0.0 => 1.0.0 
    vite: ^2.4.4 => 2.4.4 
    vue: ^2.6.12 => 2.6.12 
    vue-i18n: ^9.1.7 => 9.1.7

Screenshot

No response

Additional context

[vite-plugin-vue-i18n] Cannot read property 'message' of undefined
file: .../app/src/app_config.json
error during build:
TypeError: Cannot read property 'message' of undefined
    at Object.newOptions.onError (.../app/node_modules/@intlify/bundle-utils/lib/codegen.js:102:48)
    at Object.newOptions.onError (.../app/node_modules/@intlify/bundle-utils/lib/codegen.js:102:36)
    at newOptions.onError (.../app/node_modules/@intlify/bundle-utils/lib/codegen.js:102:36)
    at emitError (.../app/node_modules/@intlify/message-compiler/dist/message-compiler.cjs.prod.js:174:13)
    at readTokenInLinked (.../app/node_modules/@intlify/message-compiler/dist/message-compiler.cjs.prod.js:728:21)
    at readToken (.../app/node_modules/@intlify/message-compiler/dist/message-compiler.cjs.prod.js:742:20)
    at Object.nextToken (.../app/node_modules/@intlify/message-compiler/dist/message-compiler.cjs.prod.js:784:16)
    at parseLinked (.../app/node_modules/@intlify/message-compiler/dist/message-compiler.cjs.prod.js:919:31)
    at parseMessage (.../app/node_modules/@intlify/message-compiler/dist/message-compiler.cjs.prod.js:1018:36)
    at parseResource (.../app/node_modules/@intlify/message-compiler/dist/message-compiler.cjs.prod.js:1057:25)
    at Object.parse (.../app/node_modules/@intlify/message-compiler/dist/message-compiler.cjs.prod.js:1072:21)
    at Object.baseCompile (.../app/node_modules/@intlify/message-compiler/dist/message-compiler.cjs.prod.js:1380:24)
    at Object.generateMessageFunction (.../app/node_modules/@intlify/bundle-utils/lib/codegen.js:105:51)
    at Object.enterNode (.../app/node_modules/@intlify/bundle-utils/lib/json.js:96:61)
    at traverse (.../app/node_modules/jsonc-eslint-parser/lib/parser/traverse.js:45:13)
    at traverse (.../app/node_modules/jsonc-eslint-parser/lib/parser/traverse.js:49:13)

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.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
kazuponcommented, Aug 13, 2021

Is there any version of vite-plugin-vue-i18n that works with Vue 2?

Unfortunately, vite-plugin-vue-i18n is not supported for Vue 2. 😞 currently, you can migrate to Vue 3 (vue-i18n@v9.x) from Vue 2 (vue-i18n@v8.x) with vue-i18n-composable + Composition API, or @vue/compat

migration step for vue-i18n-composable + Composition API

  1. vue-i18n@8.x + Vue 2
  2. vue-i18n@8.x + @vue/composition-api + vue-composable + Vue 2 (migrate to Composition API from options API)
  3. vue-i18n@9.x + Vue 3 (if you use vite, you can use vite-plugin-vue-i18n)

migration step for Options API

  1. vue-i18n@8.x + Vue 2
  2. vue-i18n@v9.x (legacy mode) + @vue/compat
  3. vue-i18n@v9.x (legacy mode or Composition API mode) + Vue 3 (if you use vite, you can use vite-plugin-vue-i18n)
0reactions
shadow-lightcommented, Aug 13, 2021

Thanks @kazupon for clarifying, no problem. I can’t upgrade yet to Vue 3 due to other third-party dependencies. But I just moved all my <i18n> blocks into the JS section as an object instead which worked fine.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Code parser for i18next - GitHub
Key is not a string literal: the parser cannot parse variables, only literals. · Found same keys with different values: if you use...
Read more >
Typescript compiler error when importing json file
I'm finding myself in that situation, and although the fail-safe intuition would be to import the json as var config = require('./config.json') ,...
Read more >
ES2020: `import()` – dynamically importing ES modules - 2ality
The parameter is a string with a module specifier that has the same format as the module specifiers used for import declarations.
Read more >
Working with JSON in Swift - Swift Blog - Apple Developer
The JSONSerialization class method jsonObject(with:options:) returns a value of type Any and throws an error if the data couldn't be parsed.
Read more >
A Guide to React Localization with i18next | Phrase
React-i18next is a powerful set of components, hooks, and plugins that sit on top of i18next. Learn how to use it to internationalize...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found