Registry / testing / axios-better-stacktrace

axios-better-stacktrace

JSON →
library2.1.7jsnpmunverified

An axios plugin (v2.1.7) that enhances stack traces for axios errors by preserving the call site of the original request, making debugging easier. It works by wrapping axios methods to add a custom error message and the calling context to the stack trace. Currently stable with monthly-ish releases. Compared to alternatives like axios-error, it is lighter and integrates as a simple function call.

npm install axios-better-stacktrace
INSTALL
IMPORT
SIG · AXIOS-BETTER-STACK
A
axios-better-stacktrace
testingjavascriptv2.1.7
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.

axiosBetterStacktrace
import axiosBetterStacktrace from 'axios-better-stacktrace'
const axiosBetterStacktrace = require('axios-better-stacktrace')
Default import is the plugin function; ESM-only since v2, but CJS require works if you use .default.
axiosBetterStacktrace
const axiosBetterStacktrace = require('axios-better-stacktrace').default
const axiosBetterStacktrace = require('axios-better-stacktrace')
In CommonJS, you must access .default because the package exports ESM by default.
restoreAgent
const restore = axiosBetterStacktrace(axios); restore && restore()
The function returns an optional restore callback to undo the patching.

Demonstrates how to install and use the plugin with a custom axios instance to get enhanced stack traces on errors.

import axios from 'axios'; import axiosBetterStacktrace from 'axios-better-stacktrace'; const agent = axios.create(); // Apply the plugin before any interceptors axiosBetterStacktrace(agent); // Now errors will have a better stack trace agent.get('https://httpbin.org/status/404').catch(err => { console.error(err.stack); });
Debug
Known issues
breakingDefault import changed in v2: previously was a named export, now default.
fix
Use import axiosBetterStacktrace from 'axios-better-stacktrace' instead of import { axiosBetterStacktrace }.
affects: >=2.0.0
gotchaPlugin must be applied before any interceptors are added to axios instance.
fix
Call axiosBetterStacktrace(instance) immediately after creation, before adding any request/response interceptors.
affects: >=1.0.0
gotchaRestore function returns null if already restored; calling it more than once does nothing.
fix
Check restore before calling, or simply call it once.
affects: >=1.0.0
deprecatedaxios 0.x compatibility deprecated; future versions may only support axios 1.x.
fix
Upgrade axios to version 1.x.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: axiosBetterStacktrace is not a function
Using default import without .default in CommonJS
fix
const axiosBetterStacktrace = require('axios-better-stacktrace').default;
Error: Cannot find module 'axios-better-stacktrace'
Missing installation of the plugin
fix
npm install axios-better-stacktrace
Error: The module must be applied before using interceptors
Called axiosBetterStacktrace after registering interceptors
fix
Reorder code: apply plugin first, then set up interceptors.
TypeError: restoreAgent is not a function
Calling restore on a second application of the plugin (it returns null after first call)
fix
Only call restore once or check if it exists before calling.
Upgrade
Version history
2.1.7latest on npm
Audit
Dependencies
axiosrequiredpeer dependency, enhances axios errors
Agent activity
19 hits · last 30 days
node
16
OpenAI (training)
1
Resources
axios-better-stacktrace — npm install axios-better-stacktrace · libregistry