Comments (20)
The workaround (not pretty) is to use require
like:
const axiosRetry = require('axios-retry');
from axios-retry.
same issue under the TS
from axios-retry.
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.
TL;DR
Solutions for TypeScript users:
- Set
"esModuleInterop": true
intsconfig.json
and use the ES6-style importimport axiosRetry from 'axios-retry';
(refactoring required for all imports) - Use require
const axiosRetry = require('axios-retry');
(no need refactoring)
from axios-retry.
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.
I ended up doing
import axiosRetry = require('axios-retry/lib/index').default
from axios-retry.
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.
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.
seeing the same
from axios-retry.
Same here
from axios-retry.
Same issue and also seeing
Property 'isNetworkOrIdempotentRequestError' does not exist on type 'IAxiosRetry'
from axios-retry.
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.
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.
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.
Hi guys, my TS knowledge is limited... Does one of these PRs fix the issue:
?
If not, any PR is welcome!
from axios-retry.
#92 has been merged.
from axios-retry.
I still get the error axios_retry_1.default is not a function
at runtime.
from axios-retry.
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.
I still get the error "axios_retry_1.default is not a function" too
from axios-retry.
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)
- retryCondition not called anymore on HTTP 401 starting from axios-retry v3.2.0 HOT 6
- All retries have timeout of 1ms set despite not being set anywhere that way HOT 3
- What is the initial retry delay HOT 5
- Create a Security Policy HOT 1
- Success axios interceptors fired multiple times HOT 7
- [TypeScript]Unable to import names HOT 2
- Inconsistent Behavior of `isNetworkOrIdempotentRequestError` Function HOT 1
- Requiring cjs is broken since the last version (4.0.0)
- TypeError: axiosRetry is not a function in v4.0.0 HOT 11
- Module parse failed: Unexpected token (24:20) HOT 1
- Retry not working on HTTP 502 HOT 3
- How to handle errors HOT 2
- Combining `axios-retry` with other interceptors HOT 1
- [Feature request]onMaxRetryTimesExceeded to allow user to emit a custom error after retries done
- Provide option to trigger retry from successful (200) response in Axios's response interceptors HOT 4
- Do we still need `fixConfig`?
- Attach a unique id with request
- Axios-retry swallows the error response HOT 3
- Exponential delay has unnecessary final sleep HOT 2
- Introduce "axiosRetry.linearDelay"
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from axios-retry.