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

axios v0.27.0 uses node polyfills provided by webpack, which are removed from webpack v5 #4623

Closed
AhmadMayo opened this issue Apr 25, 2022 · 8 comments
Assignees

Comments

@AhmadMayo
Copy link

Describe the bug

I'm using axios in an app created by create-react-app. As soon I upgraded axios to v0.27.0, the application stop working with the error shown in the reproduction section. Downgrading to v0.26.1 solved the issue.

It looks like the issues rises from the xhr adapter.

To Reproduce

Create an empty project using CRA

npx create-react-app my-app
cd my-app

install axios

npm install axios

use axios to make any request

useEffect(() => {
  axios.get("https://google.com");
}, []);

start the application

npm start

The error is shown in the console

Module not found: Error: Can't resolve 'url' in '/home/mayo/personal-projects/my-app/node_modules/axios/lib/adapters'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "url": require.resolve("url/") }'
        - install 'url'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "url": false }
ERROR in ./node_modules/axios/lib/adapters/xhr.js 17:10-24
Module not found: Error: Can't resolve 'url' in '/home/mayo/personal-projects/my-app/node_modules/axios/lib/adapters'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "url": require.resolve("url/") }'
        - install 'url'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "url": false }

webpack compiled with 1 error

Expected behavior

That it works, or at least there are instruction to install the dependencies in the documentation.

Environment

  • Axios Version 0.27.0
  • Additional Library Versions create-react-app (react-scripts) v5 / webpack v5

Additional context/Screenshots

None

@LiangKuan4451
Copy link

I also encountered this problem, but it was solved by simply installing a "url" dependency, as suggested. I was particularly shocked.
npm i url

@Ladrillo
Copy link

I think it's this line inside xhr.js that didn't exist in v. 26

@DigitalBrainJS
Copy link
Collaborator

DigitalBrainJS commented Apr 25, 2022

@jasonsaayman #4594

@chenrihong
Copy link

I think it's this line inside xhr.js that didn't exist in v. 26

yes!

@kumardeepakme
Copy link

I also encountered this problem, but it was solved by simply installing a "url" dependency, as suggested. I was particularly shocked. npm i url

that indeed works but is not an appropriate solution.

either axios should re-bundle it in their package or there should be a better workaround.

@jasonsaayman
Copy link
Member

Fixing this right now

@KyorCode
Copy link
Contributor

KyorCode commented May 13, 2022

This should be reopened I think. The follow-redirects dependency also depends on the default webpack < 5 polyfills. Which are not present anymore.

I think

var httpFollow = require('follow-redirects').http;
this line and the next should be changed to the require('follow-redirects/http') version, so people in webpack can replace them with the build ins.

Also see browser usage in their readme file: https://www.npmjs.com/package/follow-redirects

@jasonsaayman
Copy link
Member

@KyorCode can you please put in a pull request for this?

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

8 participants