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.

Runtime only build breaks with missing keys despite formatFallback

See original GitHub issue

Reporting a bug?

Hello, recently with my team we decided to optimize vue-i18n following your guide recommendations and ended up using the official vite plugin. Now we run into an issue with runtimeOnly build where missing message key are making the app crash, despite formatFallback: true because it tries to compile the fallback message key as a string.

Expected behavior

with formatFallback: true I expect that missing message keys are not hard failing. That is a show stopper for use since our translation process is asynchronous and missing translations are common. For now, we are still including the message compiler in our build only because of this issue.

A possible fix would be to convert key: string to () => key if formatFallback && !messageCompiler

Reproduction

https://github.com/AlexandreBonaventure/vue-i18n-runtime-only

System Info

irrelevant

Screenshot

Screen Shot 2021-11-04 at 12 13 02 PM

Additional context

Thanks!

Validations

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
kazuponcommented, Nov 5, 2021

Hi! Thank you for your reporting!

As @PeterAlfredLee mentioned, you can just add the key to en.json, but it is not very desirable to crash it. Fortunately, this issue can be solved as you mentioned.

A possible fix would be to convert key: string to () => key if formatFallback && !messageCompiler

In the above condition case, the problem can be solved by modifying the code in the translate function of the core-base package to convert it to a function that just returns key in the following permalink range.

https://github.com/intlify/vue-i18n-next/blob/51263d5c6b0c3214f3ae060ae944a53d0245ac15/packages/core-base/src/translate.ts#L365-L425

0reactions
AlexandreBonaventurecommented, Nov 5, 2021

The error is thrown because you are using the runtime package vue-i18n.runtime.esm-bundler.js which don’t have messageCompiler. If you use vue-i18n.esm-bundler.js, it will print the string you pass to the t function instead of thrown a error (because it have messageCompiler).

Yes exactly I wish I could just use the runtime to reduce bundle size. I know that right now I can keep using the compiler.

Also I still think configure the key is a easy way since you have congfigured fallbacklocale: ‘en’. So you only need to add this key to en.json.

Well, not really, obviously the repo I created to highlight the issue is a minimal repro that is not really matching the complexity of a real-word use-case. Like I said our translations are handled with a third-party service and distributed accross multiple different apps. Missing keys can just happen in our setup.

you just want to print the missing key message, you can just use console.log instead of the t function.

Yes but I don’t know which key is going to be missing and don’t want to override t function or write custom logic for something that is already kind of supported. If I’m quoting your doc here: https://vue-i18n.intlify.dev/guide/essentials/fallback.html#fallback-interpolation This is exactly whay I need, but would like to be able to leverage this feature with runtime only as well

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

webpack - You are using the runtime-only build of Vue where ...
This error pops up if you try to use non-precompiled Vue templates. To fix this, set the runtimeCompiler option in vue.config.js to true...
Read more >
Missing a Key? How to Remap and Fix Your Keyboard Layout
It's clean and easy to use, though it doesn't offer the most options since certain keys like Shift and Caps Lock cannot be...
Read more >
PEP 655 – Marking individual TypedDict items as required or ...
This PEP makes no Python grammar changes. Correct usage of required and potentially-missing keys of TypedDicts is intended to be enforced only by...
Read more >
Fix "[Vue warn]: You are using the runtime-only build of Vue"
This post explains how to fix “[Vue warn]: You are using the runtime-only build of Vue where the template compiler is not available....
Read more >
vue-i18n-next - bytemeta
Runtime only build breaks with missing keys despite formatFallback. arkanario. arkanario CLOSED · Updated 1 year ago ...
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