Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot enable destructuring assignment to axios methods when apply this library

See original GitHub issue


I cannot use tough cookie jar support v 0.5.0 with axios 0.19.0. on Noe.js v10.13.0

I have tried the example you have in the but it is not working for me:

const axios = require('axios').default;

const axiosCookieJarSupport = require('axios-cookiejar-support').default;
const tough = require('tough-cookie');

const instance = axios.create({
  // WARNING: This value will be ignored.
  jar: new tough.CookieJar(),

// Set directly after wrapping instance.
instance.defaults.jar = new tough.CookieJar();

const { get, post } = instance;

The code fails here:

In the packaged lib its L73 in /lib/index.js:

Screen Shot 2019-07-01 at 11 28 48


fixed it by using instance instead of this in the anonymous function:


Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

3846masacommented, Jul 3, 2019

First, this two codes have same behavior, so my code hasn’t to modify for using normally. (See for more details)

function Test {
Test.prototype.get = function () {
const test = new Test();
function Test {
const test = new Test();
test.get = function () {

However, axios will bind this to own prototype when creating instance.

Because of that, you can apply destructuring assignment to axios methods in current version.

I know it, but this behavior isn’t basic prototype behavior, so I decide I won’t support destructuring assignment.

FYI: If you want to use destructuring assignment, you can write wrapper code to bind this as below.

import _axiosCookieJarSupport from 'axios-cookiejar-support';

function bind(instance) {
  Object.getOwnPropertyNames(instance).forEach((key) => {
    if (typeof instance[key] === 'function') {
      instance[key] = instance[key].bind(instance);

export function axiosCookieJarSupport(instance) {

  if (instance.create) {
    const create = instance.create;
    instance.create = function() {
      return bind(create.apply(this, arguments));

  return instance;
import axios from 'axios';
import { axiosCookieJarSupport } from './axios-cookiejar-support';


const { get } = axios;

akirilyukcommented, Jul 3, 2019

Thank you very much for this detailed answer!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't destructure data from axios post request response
this worked, and I was able to destructure the response. However my store seems to be adding undefined objects to the array even...
Read more >
Understanding Axios GET requests - LogRocket Blog
Learn how to make GET requests in Axios with query parameters and API keys, plus concurrent and HEAD requests and error handling.
Read more >
Cancel all axios requests in React's componentWillUnmount ...
Inside the constructor method, we assigned the cancel token source property to the source variable. source = axios.CancelToken.source();; Inside the fetchUser ...
Read more >
Boot files - Quasar Framework
Notice we are using the ES6 destructuring assignment . ... Configure aspects of libraries - An example would be to create an instance...
Read more >
Prevent Error with Default {} when Destructuring
When you use destructuring, make sure to set a default value of empty `{}` to prevent it from throwing an error...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found