Skip to content

axios 1.1.3 can't use in a library #5154

Closed

Description

@c4tc4tc4t

Describe the issue

Hi, i've created a library and it was working fine, but after the update to 1.1.3 it started to give me a bunch of the following error :
"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: { "stream": require.resolve("stream-browserify") }'
- install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "stream": false }","

I'm currently using 1.1.2 and it's working fine, but since i'm not the only one that uses the library, i'm afraid of this issue, how can i fix this? i already tried to upgraded the version of both(library and project) to 1.1.3 and doesn't work, the only thing that worked for me until now was setting everything back to 1.1.2. Help!

Example Code

No response

Expected behavior

No response

Axios Version

1.1.3

Adapter Version

No response

Browser

No response

Browser Version

No response

Node.js Version

No response

OS

No response

Additional Library Versions

angular 14.0.0

Additional context/Screenshots

No response

Activity

  1. ajmas commented on Oct 19, 2022

    @ajmas

    You may want to look at you NodeJS version and what ES version you are targeting. It sounds like something is outdated in your tool chain?

  2. AlbertAZ1992 commented on Oct 19, 2022

    @AlbertAZ1992

    It seems like the change of browser enrty with built cjs file affect more than expected?
    When axios is used to create a library as above, the dist file can not be process with tool chain, while nodejs core modules (stream, https, etc) are not be polyfilled in dist cjs file...

    v1.1.2...v1.1.3#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519R9
    image

  3. jasonsaayman commented on Oct 19, 2022

    @jasonsaayman
    Member

    Ok, will have to have a look can i be given the environment details NPM/Node versions etc

  4. c4tc4tc4t commented on Oct 19, 2022

    @c4tc4tc4t
    Author

    node v16.17.1 , it's a typescript library that i use in my angular projects, the version of Angular of my projects are all 14.0.0

  5. povilass commented on Oct 20, 2022

    @povilass

    Browsers use modules/or will transpile module maybe just add it "import": "./dist/esm/axios.js",?

  6. ajmas commented on Oct 20, 2022

    @ajmas

    I'd be concerned about needing to do a deep import of anything in a package.

    @c4tc4tc4t Are you able to create a minimal Angular project that demonstrates the issue? It may be easier for other contributors to investigate based on this?

  7. ajmas commented on Oct 20, 2022

    @ajmas

    https://github.com/c4tc4tc4t/axioslibtest

    there u go @ajmas , make sure to install on a angular project to test, you can use the function checkImportStatus to test it, the error will occur when you run ng serve

    I have never really worked with Angular, so I am not sure about the remaining recipe to be able to run this. I'd rather just focus at looking at the failure behaviour, since I don't have too much time on my hands.

  8. c4tc4tc4t commented on Oct 20, 2022

    @c4tc4tc4t
    Author

    ok, running some tests i found out that the problem is in the type AxiosResponseHeaders that comes from axios, did u guys change something with this type in this update?

  9. c4tc4tc4t commented on Oct 21, 2022

    @c4tc4tc4t
    Author

    still not figured out, acctually the lib that i created does not contain the error, my bad sry, but the actual lib i cant post it

  10. c4tc4tc4t commented on Oct 21, 2022

    @c4tc4tc4t
    Author

    i'll try to code a lib with the problem, now that i have a notion of what it is and a angularproject, so you guys can just clode the project and install the lib and have a better understading of what's going on, give me time to do it.

  11. c4tc4tc4t commented on Oct 21, 2022

    @c4tc4tc4t
    Author

    Ok, so what you have to do is create a Angular 14.0.0 project, then run "npm install https://github.com/c4tc4tc4t/poketeste" , i will install my typescript library that contains only one function, install axios in the Angular project and import the lib "import * as poke from 'axiosteste'", axiosteste is the name of my lib, try a console.log(poke.pokemon()); , if u run ng serve, you will get my error, waiting for some help on this, and of course if u change the version of axios on my lib and the project back to 1.1.2 everything works fine!

  12. povilass commented on Oct 23, 2022

    @povilass

    Well this changed
    image

    Kinda destroyed what's use for browser and node platform because

    axios\dist\node\axios.cjs

    Got this
    image

    And axios\dist\axios.js got this
    image

    So this change must be reverted....

  13. krzaczek commented on Oct 23, 2022

    @krzaczek

    We have the same problem with our React app. We have been using axios since 0.19 and 1.1.3 breaks our webpack build. Reverting to 1.1.2 fixes the problem for
    now but this needs to be fixed.

  14. 1 remaining item

  15. krutoo commented on Oct 27, 2022

    @krutoo

    i have same issue, can someone tell how to fix that with 1.1.3 (without downgrade to 1.1.2)?

  16. jlombardo-tableau commented on Oct 27, 2022

    @jlombardo-tableau

    yes, we need an actual fix for this, not to just revert to 1.1.2 in our code.

  17. ajmas commented on Oct 27, 2022

    @ajmas

    Given this issue isn't really fixed and instead only has a downgrade as workaround, we should probably keep this ticket open?

  18. added a commit that references this issue on Nov 4, 2022
  19. added a commit that references this issue on Nov 11, 2022
  20. KubaLorenc commented on Jan 3, 2023

    @KubaLorenc

    It works well with 1.2.0 version, but is broken again in 1.2.2

  21. ajmas commented on Jan 3, 2023

    @ajmas

    @KubaLorenc does it break in the same way as before the fix? If not, can you describe the failure mode?

  22. mevan-aiken commented on Apr 6, 2023

    @mevan-aiken

    I have the same problem when used in a library I am developing and after importing and using it in a CRA app. Its displays pollyfill errors (stream, https, zlib etc), I am using 1.3.5 v of axios. Is there any solution for this?

  23. ajmas commented on Apr 6, 2023

    @ajmas

    Can you share the errors? Did you try adding the polyfill it is complaining about, as a package dependency?

  24. mevan-aiken commented on Apr 7, 2023

    @mevan-aiken

    @ajmas Yes I added all the complaining polyfills, some errors were resolved but still there are more errors displaying as below. When I remove any use of axios in my library and imported the updated version to the sample app then the pollyfill errors are gone. Therefore I identified these polyfill errors come due to use of Axios (1.3.5)

    If you want to include a polyfill, you need to:
    	- add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }'
    	- install 'stream-browserify'
    

    The above same error is displaying for stream-http, https-browserify, fs, tty-browserify, os-browserify, browserify-zlib.

  25. ajmas commented on Apr 12, 2023

    @ajmas

    @mevannir Are you able to create a sample project that demonstrates this issue? It would make it easier to analyse what is going on and seeing if there is a workaround too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions