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.

Cannot use with vue-class-component

See original GitHub issue

Reporting a bug?

In case of Options API vue-i18n-loader parses the <i18n></i18n> section and generates code that puts the result into component object itself. It works for Options API + JS, but breaks when using vue-class-component because in that case component options are not the component object itself, but it’s “__o” property.

Expected behavior

Code generated by vue-i18n-loader checks if __o prop exists on the component object and puts translations into it if it does.

Reproduction

https://github.com/SniperJoe/vue-i18n-loader-repro

Issue Package

vue-i18n-loader

System Info

System:
    OS: Linux 5.11 Ubuntu 21.04 (Hirsute Hippo)
    CPU: (16) x64 AMD Ryzen 7 3800X 8-Core Processor
    Memory: 2.01 GB / 31.35 GB
    Container: Yes
    Shell: 5.1.4 - /bin/bash
  Binaries:
    Node: 12.21.0 - /usr/bin/node
    npm: 8.3.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 93.0.4577.82
    Firefox: 92.0
  npmPackages:
    @intlify/vue-i18n-loader: ^3.2.0 => 3.3.0 
    vue: ^3.2.0 => 3.2.21 
    vue-i18n: ^9.2.0-beta.11 => 9.2.0-beta.17 
    webpack: ^5.44.0 => 5.62.1

Screenshot

No response

Additional context

The workaround I use is to edit bundle-utils/lib/json.js:

<..>
                        generator.push(`${exportSyntax} function (Component) {`);
                        generator.indent();
                        generator.pushline(`const newI18N = (${componentNamespace}__o ? ${componentNamespace}__o.${variableName} : ${componentNamespace}${variableName}) || []`);
                        generator.pushline(`${componentNamespace}${variableName} = ${componentNamespace}${variableName} || []`);
                        generator.push(`newI18N.push({`);
                        generator.indent();
                        generator.pushline(`"locale": ${JSON.stringify(localeName)},`);
                        generator.push(`"resource": `);
<..>
                        generator.push(`if (${componentNamespace}__o) {`);
                        generator.indent();
                        generator.push(`${componentNamespace}__o.${variableName} = newI18N;`);
                        generator.deindent();
                        generator.push(`} else {`);
                        generator.indent();
                        generator.push(`${componentNamespace}${variableName} = newI18N;`);
                        generator.deindent();
                        generator.push(`}`);

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:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
SniperJoecommented, Dec 14, 2021

@kazupon please take a look at the PR

0reactions
SniperJoecommented, Dec 16, 2021

@kazupon it works! Thank you very much for collaboration 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't resolve "vue-class-component" - Syncfusion
Hello,I am getting an error from all the components where vue-component is used. ``` warning in ./node_modules/@syncfusion/ej2-vue-splitbuttons/ ...
Read more >
Deprecate vue-class-component · Issue #569 - GitHub
In conclusion, my suggestion is to deprecate vue-class-component and do not further suggest new developers using it. There is no point to ...
Read more >
Why my vue3 could not work with vue-class-component
Component doesn't support in Vue3. So instead of Component you can use Options and if there is any Component you can define them...
Read more >
Data - Vue Class Component
To avoid this, you can use null value or use data hook instead: import Vue from 'vue' import Component from 'vue-class-component' @Component export...
Read more >
cannot find module 'vue-class-component' - You.com
I have a fresh project which I created using the vue command line tool. vue create . But when I type npm serve,...
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