-
Notifications
You must be signed in to change notification settings - Fork 169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: export of type definitions, depending on whether it is ES Module or CommonJS #250
feat: export of type definitions, depending on whether it is ES Module or CommonJS #250
Conversation
"require": { | ||
"types": "./lib/cjs/index.d.ts", | ||
"default": "./index.js" | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By using Conditional exports
, the type definition of the imported axios will be switched within the type definition in each case of CommonJS and ES Module. This eliminates compilation errors.
Incidentally, I don't think there will be any impact on the existing use of JavaScript. Because Conditional exports
was already in use.
@@ -1,6 +1,6 @@ | |||
import * as axios from 'axios'; | |||
|
|||
export = IAxiosRetry; | |||
export default IAxiosRetry; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when use =
, below error occur. So, i change to default
.
error TS1192: Module '"/home/study/workspace/ts-node-oidc/node_modules/axios-retry/lib/esm/index"' has no default export.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the reason for why an import like:
import { IAxiosRetryConfig } from 'axios-retry'
no longer works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yutak23 how/when did you get that error? Did it work with version of axios-retry prior to your change?
I'm thinking that we could just revert to the old code if your error was not introduced by these changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When compiling to CommonJS, export =
is fine, but when compiling to ES Module, export =
will result in the following error Therefore, we changed it to default export.
#250 (comment)
However, the modification to export IAxiosRetryConfig
etc. for name import was omitted. Sorry about that. I have uploaded the fix in the #252.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did export =
really create an issue and in what circumstances? I haven't seen issues after changing it in this project and building.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't seen issues after changing it in this project and building.
I would be very grateful if you could provide me with details of the configuration information for your TypeScript project.
The problem I am talking about happens when compiling to ES Module with ES Module configuration (set type: module
in package.json)
When export =
, the following compile error occurs. When export default
is used, no error occurs.
My environment is below.
// package.json
"type": "module",
"dependencies": {
"axios": "^1.6.2",
"axios-retry": "^3.9.0",
},
"devDependencies": {
"@tsconfig/node16": "^16.1.1",
"@tsconfig/strictest": "^2.0.2",
"typescript": "~5.2.2",
}
// tsconfig.json
{
"extends": ["@tsconfig/node16/tsconfig.json", "@tsconfig/strictest/tsconfig.json"],
"compilerOptions": {
"outDir": "dist",
"declaration": true,
"sourceMap": true
},
"include": ["srv/**/*.ts"],
"exclude": ["node_modules", "dist"]
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My question is: did this work before (before v3.9.0)?
Because if not then there is not really a need to change that now. Could do that in next major version if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is already becoming Revert's policy, but I think it would be rude not to answer your question, so I want to answer.
The type definition used to be export default
and it worked except for the ES Module. . However, this had a problem with issue and has been modified. But then another problem arose and more changes were made.
Line 66 in 0f50dc9
export default axiosRetry; |
Looks great, I'm publishing this as a minor |
Thanks a lot! published as 3.9.0 |
I haven't had time to look into those changes yet but it appears to break the import I had import { IAxiosRetryConfig } from 'axios-retry' |
@rchl can you please open an Issue with all the details? |
This ought to fix #159.
The intent of this change is detailed in the issue.
#159 (comment)
The following tests were performed to verify that axios-retry is available for all patterns.
environment