Registry / api-client / axios-inherit

axios-inherit

JSON →
library1.0.1jsnpmunverified

axios-inherit (v1.0.1, stable, low release cadence) is a small utility that adds interceptor inheritance to axios. It ensures that any existing interceptors on the global axios instance are inherited by new instances created via axios.create(), and that new interceptors added to the global instance are applied to already existing instances. It also handles interceptor removal. This solves a common pain point when using axios across modules or configuring shared interceptors. It is available on npm, ships TypeScript types, and has a minimal API surface. Similar functionality can be achieved manually, but axios-inherit provides a simple drop-in solution.

npm install axios-inherit
INSTALL
IMPORT
SIG · AXIOS-INHERIT
A
axios-inherit
api-clientjavascriptv1.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import axiosInherit from 'axios-inherit'
const axiosInherit = require('axios-inherit')
Package is ESM-first; use import syntax. For CommonJS, use dynamic import.

Shows how to install and enable interceptor inheritance on global axios, create a new instance, and add a request interceptor that automatically propagates.

import axios from 'axios'; import axiosInherit from 'axios-inherit'; // Enable inheritance on the global axios instance axiosInherit(axios); // Now any new instance created via axios.create() will inherit interceptors const instance = axios.create({ baseURL: 'https://api.example.com' }); // Adding an interceptor on the global instance after instances exist axios.interceptors.request.use(config => { config.headers['Authorization'] = 'Bearer ' + (process.env.API_KEY ?? ''); return config; }); // The interceptor is automatically applied to 'instance' as well instance.get('/endpoint').then(response => console.log(response.data));
Debug
Known issues
breakingaxios-inherit mutates the global axios object and all created instances; ensure you call it before any instance creation or interceptor usage.
fix
Call axiosInherit(axios) at the earliest point in your application, before creating any instances or adding interceptors.
affects: >=1.0
gotchaThe package only works with axios instances created via axios.create(); it does not affect interceptors added directly on custom objects that are not axios instances.
fix
Use axios.create() to create instances you want to be inheritable.
affects: >=1.0
gotchaInterceptors added before calling axiosInherit(axios) on the global instance will not be inherited by new instances created later.
fix
Call axiosInherit(axios) before adding any interceptors to the global instance.
affects: >=1.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'interceptors')
axiosInherit was called before importing axios or on a non-axios object.
fix
Ensure axios is imported and the function is called with the axios module object: import axios from 'axios'; import axiosInherit from 'axios-inherit'; axiosInherit(axios);
Module not found: Can't resolve 'axios-inherit'
Package not installed or import path incorrect.
fix
Run npm install axios-inherit and use correct import: import axiosInherit from 'axios-inherit';
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
44 hits · last 30 days
node
36
OpenAI (training)
1
Resources
axios-inherit — npm install axios-inherit · libregistry