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

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

Closed
4 tasks done
shadow-light opened this issue Aug 10, 2021 · 5 comments
Closed
4 tasks done
Labels
Status: Need More Info Lacks enough info to make progress

Comments

@shadow-light
Copy link

Reporting a bug?

I did not set the include config param since I don't use any translation files and just use 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.
@shadow-light shadow-light added the Status: Review Needed Request for review comments label Aug 10, 2021
Copy link
Member

kazupon commented Aug 10, 2021

Thank you for your reporting!
Unfortunately, I could not reproduce the same issue in my environment.

So, In order for us to find the cause, we need a repo to reproduce.
Could you give us a minimal reproduction environment, please?

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

I've found out some stuff from your npm packages that are installed in your environment.
vue-i18n@v9.x support for Vue 3 only.
I seem Vue 2.x is installed in your environment.
and, @intlify/vue-i18n-loader too.

I'm curious what your environment looks like.
It looks like you have a mix of environments built with Vue CLI and vite.
Once you have Vue 3, vue-i18n@v9.x, vite and @intlify/vite-plugin-vue-i18n, so it’s installed with npm init vite@latest.
Could you please check if the same issue occurs in your environment?

@kazupon kazupon added Status: Need More Info Lacks enough info to make progress and removed Status: Review Needed Request for review comments labels Aug 10, 2021 — with Volta.net
@shadow-light
Copy link
Author

Yes was trying to migrate to vite from webpack and later discovered v9 isn't compatible with Vue2. No worries, I assume it might be due to the version mismatch. Someone can reopen if they encounter it too.

@shadow-light
Copy link
Author

shadow-light commented Aug 13, 2021

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

I've got everything working except for i18n as messages are not loading from blocks like they were in Webpack. I instead get missing key errors.

(I've downgraded to vue-i18n 8.25.0 already)

Copy link
Member

kazupon commented 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)

@shadow-light
Copy link
Author

shadow-light commented 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Need More Info Lacks enough info to make progress
Projects
None yet
Development

No branches or pull requests

2 participants