Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
addGlobals
✓ import addGlobals from 'vue-add-globals'
✗ import { addGlobals } from 'vue-add-globals'
The `addGlobals` function is a default export.
addGlobals (CommonJS)
✓ const addGlobals = require('vue-add-globals')
While examples show ESM, CommonJS `require` is also typically supported for older Node.js environments and build setups where this package would have been relevant.
Demonstrates adding a global method and property to a Vue instance using `addGlobals` for testing or isolated environments, emphasizing its Vue 2 context.
import addGlobals from 'vue-add-globals'
import { createApp } from 'vue'
// NOTE: This utility is for Vue 2. The example below uses Vue 2 concepts.
// For demonstration purposes, we'll simulate a Vue 2 context.
// Simulate a Vue 2 like constructor for demonstration
class MockVue {
constructor() {}
extend() {
return class MockExtendedVue {
constructor() {}
$mount() { return this; }
}
}
}
// In a real Vue 2 app, you would import Vue directly:
// import Vue from 'vue'
// const freshVue = Vue.extend();
const freshVue = new MockVue().extend(); // Simulate Vue.extend()
const $mockedMethod = () => ({ message: 'Hello from mock!' })
const mockedProp = 'Test Prop Value'
addGlobals(freshVue, {
$mockedMethod: $mockedMethod,
mockedProp: mockedProp
})
// Simulate a component using these globals
const TestComponent = {
template: '<div></div>',
mounted() {
console.log('Method result:', this.$mockedMethod());
console.log('Property value:', this.mockedProp);
}
};
// Simulate mounting the component
const vm = new freshVue(TestComponent).$mount();
// Expected output in console:
// Method result: { message: 'Hello from mock!' }
// Property value: Test Prop Value
Debug
Known issues
breakingThis package is designed for Vue 2's global constructor API. It is incompatible with Vue 3, which uses an application instance API (`createApp`) and `app.config.globalProperties` for global registration. Attempting to use it with Vue 3 will not work as expected.fixFor Vue 3, use `app.config.globalProperties` or `app.mixin` on the application instance returned by `createApp()`.
affects: All versions, when used with Vue 3
deprecatedThe `vue-add-globals` package is no longer actively maintained. Its GitHub repository has been archived, indicating it will receive no further updates, bug fixes, or security patches. Users should consider alternatives or be aware of the risks of using abandoned software.fixMigrate to a different solution or consider the implications of using unmaintained software. For testing Vue 2, manually mock global properties if `Vue.extend()` is insufficient.
affects: >=2.0.1
gotchaModifying the global `Vue` constructor directly can lead to unintended side effects across multiple tests or components. The `README` recommends using `Vue.extend()` to create a fresh, isolated Vue constructor for modifications.fixAlways apply `addGlobals` to a fresh instance created with `Vue.extend()` (e.g., `addGlobals(Vue.extend(), {...})`) rather than directly to the main `Vue` object, especially in test environments. affects: All versions
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading '$someMethod') or 'this.$someMethod is not a function'
This typically occurs when `vue-add-globals` is used with a Vue 3 application, where the global properties API has changed, or if the `addGlobals` call was not applied to the correct Vue instance/constructor.
fixEnsure you are using Vue 2. If using Vue 2, verify that `addGlobals` was called on the `Vue` constructor or a `Vue.extend()` instance *before* components that rely on these globals are created.
Error: Vue.config.silent is not a function / TypeError: Vue.config.warnHandler is not a function
This package is designed for Vue 2. Attempting to use it with Vue 3 may lead to errors when the internal `vue-add-globals` logic tries to access Vue 2-specific properties or methods on a Vue 3 instance.
fixThis package is incompatible with Vue 3. Use Vue 3's native `app.config.globalProperties` or `app.mixin` for global functionality.
Audit
Dependencies
vuerequiredThis package is designed to operate on a Vue instance or constructor, primarily Vue 2. It's usually a peer/dev dependency for projects using this utility.