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

TypeError: Cannot redefine property: $i18n #421

Closed
HadiChen opened this issue Sep 3, 2018 · 11 comments · Fixed by #422
Closed

TypeError: Cannot redefine property: $i18n #421

HadiChen opened this issue Sep 3, 2018 · 11 comments · Fixed by #422
Labels
Type: Bug Bug or Bug fixes

Comments

@HadiChen
Copy link

HadiChen commented Sep 3, 2018

vue & vue-i18n version

ex: 2.5.17, 8.0.0
vue:2.5.17
vue-i18n:8.0.0
nuxt.js:1.4.2

Reproduction Link

Steps to reproduce

What is Expected?

image

What is actually happening?

Object.defineProperty(Vue.prototype, '$i18n', {

  Object.defineProperty(Vue.prototype, '$i18n', {
    get () { return this._i18n }
  })

fix bug edit

if (!Vue.prototype.hasOwnProperty('$i18n')) {
  Object.defineProperty(Vue.prototype, '$i18n', {
    get () { return this._i18n }
  })
}
@BorjaRafols
Copy link

I can confirm that this fixes the problem, any idea on when it will get merged into master?

@jgribonvald
Copy link

Me too I confirm this solve the problem !

@kazupon
Copy link
Owner

kazupon commented Sep 25, 2018

@jgribonvald
Hi!
sorry for my late response.

There is a possibility that this problem is caused by the vue-i18n build setting problem.

1a1958a

Would you be able to try to use the dist files (dist/*.js) that build with build confg of dev branch please?
https://kazupon.github.io/vue-i18n/installation.html#dev-build

@jgribonvald
Copy link

jgribonvald commented Sep 25, 2018

@kazupon
Hi and thanks to respond !
Else I'm sorry this doesn't change anything:

TypeError: can't redefine non-configurable property "$i18n"
ObjectOrReflectDefineProperty ...
defineProperty ...
extend ...
install ...
$n.use https://unpkg.com/vue@2.5.17/dist/vue.min.js:6:34186
__webpack_require__ ...
<anonyme> ...
<anonyme> ...
InnerModuleEvaluation  ...
ModuleEvaluate ...

I've updated the fiddle : https://jsfiddle.net/jgribonvald/cmyk6Lua/

@kazupon
Copy link
Owner

kazupon commented Sep 25, 2018

@jgribonvald
Thank you for your chekcing! 🙇
I've updateed dev branch.
6d5ec61

Could you try the checking now please? 🙏

@kazupon kazupon added the Type: Bug Bug or Bug fixes label Sep 25, 2018
@jgribonvald
Copy link

@kazupon sorry for the delay
Nothing better, here is the trace of the error:

Uncaught TypeError: Cannot redefine property: $i18n
    at Function.defineProperty (<anonymous>)
    at extend (...)
    at Function.install (...)
    at Function.$n.use (VM169 vue.min.js:6)
    at Module.5a74

@kazupon
Copy link
Owner

kazupon commented Sep 28, 2018

@jaredzhu1993
Hi!

I found the strange javascript codes in your jsfiddle reproduction.
In javascript of jsfiddle, VueI18n had been doubly bundled. 🤔

Could you provide the minimum reproduction codes with repository please? 🙏

@jgribonvald
Copy link

jgribonvald commented Oct 9, 2018

In my mind the problem is that we have 2 web components (that are 2 repositories) including their dependency of vue-i18n, and so as it's builded and loaded separately they try to load twice vue-i18n whereas there is only on vuejs instance.
I'm not really competent in this part, but that i can say is that the fix

if (!Vue.prototype.hasOwnProperty('$i18n')) {
  Object.defineProperty(Vue.prototype, '$i18n', {
    get () { return this._i18n }
  })
}

is working ! It means that it check that vue-i18n isn't already registered into vuejs.

On an other side why not having an independant plugin ? used as a service...

here a new jsfiddle : https://jsfiddle.net/jgribonvald/j4zq58dy/ and look at console
sources are here: https://github.com/uPortal-contrib/uPortal-web-components

@kazupon
Copy link
Owner

kazupon commented Oct 12, 2018

I have released v8.1.1
please try it.

@jgribonvald
Copy link

this doesn't not solve the problem
vue-i18n should manage several web-components (and not related/on same project ) trying each one to configure $i18n attribute on their own : TypeError: can't redefine non-configurable property "$i18n"
After it was setted all components trying to do the same configuration will get the error

kazupon pushed a commit that referenced this issue Oct 14, 2018
@HadiChen

* fix TypeError: Cannot redefine property: $i18n

fix #421

* flow:$FlowFixMe with object literal
@jgribonvald
Copy link

@kazupon : thanks a lot !

etherdog-eth pushed a commit to etherdog-eth/vue-i18n that referenced this issue May 31, 2021
@HadiChen

* fix TypeError: Cannot redefine property: $i18n

fix kazupon/vue-i18n#421

* flow:$FlowFixMe with object literal
wdavis122 added a commit to wdavis122/vue-i18n that referenced this issue Jun 5, 2024
@HadiChen

* fix TypeError: Cannot redefine property: $i18n

fix kazupon/vue-i18n#421

* flow:$FlowFixMe with object literal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Bug or Bug fixes
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants