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

[vue-i18n] already installed. #290

Closed
emileber opened this issue Jan 31, 2018 · 0 comments
Closed

[vue-i18n] already installed. #290

emileber opened this issue Jan 31, 2018 · 0 comments

Comments

@emileber
Copy link
Contributor

vue-i18n is installing itself on the window even when imported as a module

vue & vue-i18n version

I'm using 7.4.1 but it's not necessarily new to this version.

Steps to reproduce

Load Vue via a script tag, then use another version of Vue in a bundled file (which exposes no globals).

<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.28/vue.min.js"></script>
<script src="bundle-using-vue-2.js"></script>

Within the bundle, use vue-i18n.

import Vue from 'vue';
import VueI18n from 'vue-i18n';

Vue.use(VueI18n);

What is Expected?

vue-i18n to be installed only with my bundle's vue 2.

What is actually happening?

Two warnings and the installation fails with my bundle's Vue.

[vue-i18n] vue-i18n (undefined) need to use Vue 2.0 or later (Vue: 1.0.28).
[vue-i18n] already installed.

After examining the vue-i18n.esm.js source, it looks like it's installing itself by default on the global Vue instance.

if (typeof window !== 'undefined' && window.Vue) {
  window.Vue.use(VueI18n);
}

To avoid this, Vuex installs itself with the global Vue instance only if it was not installed yet with another Vue instance. (source)

var Vue; // bind on install

var Store = function Store (options) {
  var this$1 = this;
  if ( options === void 0 ) options = {};

  // Auto install if it is not done yet and `window` has `Vue`.
  // To allow users to avoid auto-installation in some cases,
  // this code should be placed here. See #731
  if (!Vue && typeof window !== 'undefined' && window.Vue) {
    install(window.Vue);
  }

And the install function uses the Vue variable.

function install (_Vue) {
  if (Vue && _Vue === Vue) {
    if (process.env.NODE_ENV !== 'production') {
      console.error(
        '[vuex] already installed. Vue.use(Vuex) should be called only once.'
      );
    }
    return
  }
  Vue = _Vue;
  applyMixin(Vue);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant