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

Any plans to add support for axios v1? #7

Open
crhistianramirez opened this issue Aug 30, 2023 · 7 comments
Open

Any plans to add support for axios v1? #7

crhistianramirez opened this issue Aug 30, 2023 · 7 comments

Comments

@crhistianramirez
Copy link

I understand that its not currently meant to support axios v1+ but I think there will be a growing number of people that are looking for that functionality.

@crhistianramirez
Copy link
Author

Actually, upon further investigation I was able to get this package to work with axios v1+

Looks like the main issue is that it is referencing some library helpers that are no longer exported in v1.x, but are still accessible in node_modules. I think it was an oversight that its no longer exported, you can track that bug here

But, basically since the files are still available you can just update the webpack resolve alias to pull them in. Here's what it looks like in next.js, vite has a similar capability.

const path = require("path");

/** @type {import('next').NextConfig} */
const nextConfig = {
  webpack: (config) => {
    config.resolve.alias = {
      ...config.resolve.alias,
      // Fix: Missing "./lib/helpers" specifier in "axios" package
      "axios/lib": path.resolve(__dirname, "./node_modules/axios/lib"),
    };

    return config;
  },
};

module.exports = nextConfig;

Then it was just a matter of ignoring the peer dependency warnings with npm install --legacy-peer-deps. Although, since there is technically a workaround, if we document it, then maybe we can widen the supported axios range. What do you think?

@cuibonobo
Copy link
Member

Thanks for raising this! I have been pretty busy but I will happily review a PR for any documentation changes that you suggest.

@crhistianramirez
Copy link
Author

Sounds good, also pretty busy at the moment but I'll plan to make a PR in the following weeks.

@cuibonobo
Copy link
Member

I'm not too familiar with the specific context where this workaround is needed. I also noticed that the linked Axios bug has been closed... @crhistianramirez is this workaround still needed? If so, can you respond with a 1 or 2 sentence explanation on the situation where this workaround would be needed?

@Walledgarden
Copy link

Any updates on that?

@crhistianramirez
Copy link
Author

crhistianramirez commented Jan 16, 2024

@cuibonobo this workaround is needed if you want to use axios-fetch-adapter with axios 0.x

The reason this is needed is because in axios 0.x a number of helper methods were publicly available and used by axios-fetch-adapter such as buildURL. This basically includes anything under axios/lib/helpers

Upon further investigation I discovered that the code and methods are still available in axios v1 they just aren't exported for public consumption. My workaround updates the build configuration to make that code available. In my example, I did it for Next.js. That issue I linked demonstrates it for Vite. This wouldn't be a code change but rather an update to the README of this package.

The issue as you mentioned is closed but without resolution. Here is a link to a comment outlining their thoughts around this

@KaKi87
Copy link

KaKi87 commented Feb 21, 2024

Importing lib methods is now possible by replacing /lib/ with /unsafe/ as per axios/axios#5677.

Thanks

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

No branches or pull requests

4 participants