Skip to content
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

fix problem with named export axios and Typescript NodeNext #5288

Closed
wants to merge 9 commits into from

Conversation

akphi
Copy link

@akphi akphi commented Nov 20, 2022

Instructions

Note: I'm reopening #5104 as I have tried to mention there that the fix you mentioned doesn't actually work for all cases.

Fixes #5101

I also chucked in a small fix for the default export to work with NodeNext, a bit of context here

microsoft/TypeScript#49298
microsoft/TypeScript#50690

Basically, I will make it so people can import axios as a named import rather than having to do something like:

import { default as axios } from 'axios';

UPDATE: I saw you have already taken care of #5101 by updating exports in package.json, but the problem with named exports remains. Please see my repro here akphi/issue-repo#12

I don't think import { axios } from 'axios'; work at all in my case and I'm pretty sure this should help fixes #5101

@jasonsaayman
Copy link
Member

Please re-check this should be solved, if not @ me and I will have a look again

@akphi
Copy link
Author

akphi commented Dec 2, 2022

@jasonsaayman I just updated my repro akphi/issue-repo#12 to use axios@1.2.0, I got the same error

src/index.ts:1:10 - error TS2724: '"axios"' has no exported member named 'axios'. Did you mean 'Axios'?

1 import { axios } from "axios";
           ~~~~~

  node_modules/axios/index.d.ts:432:14
    432 export class Axios {
                     ~~~~~
    'Axios' is declared here.


Found 1 error in src/index.ts:1

@jasonsaayman jasonsaayman reopened this Dec 2, 2022
@DigitalBrainJS
Copy link
Collaborator

Yes, Axios exports its factory only as a default export, and all other exported properties defined in the factory are also available as named export. It seems like this behavior has a logical fit with the existing commonjs interface. Basically, it's not a big deal to re-export the factory as a named export too, but historically Axios had only default export, so all the tutorials are written for default export. I may be wrong, but having axios and Axios as named export might confuse some users.

@akphi
Copy link
Author

akphi commented Dec 15, 2022

@DigitalBrainJS is there anything else you want me to do on this PR?

@akphi
Copy link
Author

akphi commented Dec 20, 2022

will close this for now

@akphi akphi closed this Dec 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Jest tests failed after upgrading axios to v1.1.2
3 participants