Git Product home page Git Product logo

Comments (20)

philjones88 avatar philjones88 commented on July 29, 2024 11

The workaround (not pretty) is to use require like:

const axiosRetry = require('axios-retry');

from axios-retry.

dmitrirussu avatar dmitrirussu commented on July 29, 2024 10

same issue under the TS

from axios-retry.

mattwexa avatar mattwexa commented on July 29, 2024 7

I think what is missing is something in the README to say that this library requires esModuleInterop to be true. In that case, I suggest that this issue be closed and I'll create a pull request to add documentation. Does that sound ok? @softonic @philjones88

from axios-retry.

MaksimKiselev avatar MaksimKiselev commented on July 29, 2024 3

TL;DR

Solutions for TypeScript users:

  • Set "esModuleInterop": true in tsconfig.json and use the ES6-style import import axiosRetry from 'axios-retry'; (refactoring required for all imports)
  • Use require const axiosRetry = require('axios-retry'); (no need refactoring)

from axios-retry.

slinkardbrandon avatar slinkardbrandon commented on July 29, 2024 3

My team ran into this error today as well when trying to use the library. Our "solution" is below:

- import axiosRetry, { exponentialDelay, isNetworkOrIdempotentRequestError } from 'axios-retry';
+ import { exponentialDelay, isNetworkOrIdempotentRequestError } from 'axios-retry';
+ const axiosRetry = require('axios-retry');

I poked around the axios-retry source a little bit today too. I ran the build command in the package.json file, it generates a lib directory with an index.js file, that lib/index.js file then gets required by the project root index.js.

The post-babel output lib/index.js file declares a exports.default along with a few others..

'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.isNetworkError = isNetworkError;
exports.isRetryableError = isRetryableError;
exports.isSafeRequestError = isSafeRequestError;
exports.isIdempotentRequestError = isIdempotentRequestError;
exports.isNetworkOrIdempotentRequestError = isNetworkOrIdempotentRequestError;
exports.exponentialDelay = exponentialDelay;
exports.default = axiosRetry;

// ... more code

function axiosRetry(axios, defaultOptions) {
  axios.interceptors.request.use(function (config) {
    var currentState = getCurrentState(config);
    currentState.lastRequestTime = Date.now();
    return config;
  });

  // ... more code
}

// ... more code

I forked the repo thinking this would be a super simple adjustment that I could patch up but the variable and function declarations are really strange to me and I had a hard time wrapping my head around them.

I would probably propose changing the whole export structure & stop adding object properties to a function under the hood, but that feels extreme for what should have been a really simple fix. Does anyone have any additional thoughts or guidance here?

from axios-retry.

ChavaSobreyra avatar ChavaSobreyra commented on July 29, 2024 1

I ended up doing
import axiosRetry = require('axios-retry/lib/index').default

from axios-retry.

frosas avatar frosas commented on July 29, 2024 1

Another ugly hack in case you don't want to lose the type checking:

import importedAxiosRetry from 'axios-retry';

const axiosRetry: typeof importedAxiosRetry = require('axios-retry');

from axios-retry.

rastilin avatar rastilin commented on July 29, 2024 1

@slinkardbrandon

Thanks for your post. Our Cordova project doesn't have a defined .ts file to apply settings but your import method worked to solve the problem.

from axios-retry.

ChavaSobreyra avatar ChavaSobreyra commented on July 29, 2024

seeing the same

from axios-retry.

philjones88 avatar philjones88 commented on July 29, 2024

Same here

from axios-retry.

threesquared avatar threesquared commented on July 29, 2024

Same issue and also seeing

Property 'isNetworkOrIdempotentRequestError' does not exist on type 'IAxiosRetry'

from axios-retry.

mattwexa avatar mattwexa commented on July 29, 2024

Hi, I had the same error. I solved it by setting "esModuleInterop": true in tsconfig.json and using the ES6-style import import axiosRetry from 'axios-retry';. This setting is recommended according to the official TypeScript website

I'll open an issue for the missing types.

from axios-retry.

nandafirmans avatar nandafirmans commented on July 29, 2024

this is works for me

import * as axios from 'axios'

declare function axiosRetry(
  axios: axios.AxiosStatic | axios.AxiosInstance,
  axiosRetryConfig?: axiosRetry.IAxiosRetryConfig
): void

declare namespace axiosRetry {
  interface IAxiosRetryConfig {
    /**
     * The number of times to retry before failing
     * default: 3
     *
     * @type {number}
     */
    retries?: number,
    /**
     * Defines if the timeout should be reset between retries
     * default: false
     *
     * @type {boolean}
     */
    shouldResetTimeout?: boolean,
    /**
     * A callback to further control if a request should be retried. By default, it retries if the result did not have a response.
     * default: error => !error.response
     *
     * @type {Function}
     */
    retryCondition?: (error: axios.AxiosError) => boolean,
    /**
     * A callback to further control the delay between retry requests. By default there is no delay.
     *
     * @type {Function}
     */
    retryDelay?: (retryCount: number, error: axios.AxiosError) => number
  }
}

export = axiosRetry

from axios-retry.

dinvlad avatar dinvlad commented on July 29, 2024

Would it be possible to take another look at this? We still get the error axios_retry_1.default is not a function. Thanks!

from axios-retry.

mawrkus avatar mawrkus commented on July 29, 2024

Hi guys, my TS knowledge is limited... Does one of these PRs fix the issue:

?

If not, any PR is welcome!

from axios-retry.

mawrkus avatar mawrkus commented on July 29, 2024

#92 has been merged.

from axios-retry.

s5no5t avatar s5no5t commented on July 29, 2024

I still get the error axios_retry_1.default is not a function at runtime.

from axios-retry.

jcass8695 avatar jcass8695 commented on July 29, 2024

I am also getting this error when esModuleInterop: true is not used. Closing my initial issue #143 in favour of this one.

from axios-retry.

lucasnishimura avatar lucasnishimura commented on July 29, 2024

I still get the error "axios_retry_1.default is not a function" too

from axios-retry.

mindhells avatar mindhells commented on July 29, 2024

This issue should be fixed with the latest updates.
Please, feel free to reopen it in case you experience this issue again.

from axios-retry.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.