Skip to content

Force axios to use the http adapter instead of xhr #5263

Closed

Description

@dysolix

Is your feature request related to a problem? Please describe.

I am creating a library that will mostly be used in electron projects. The library needs to perform http request to a localhost server that uses a self signed certificate, so I need to use https.Agent. The problem is, that axios uses the xhr adapter instead of the http adapter. When i try to import the correct adapter from axios/lib/adapters/http I get the error ERR_PACKAGE_PATH_NOT_EXPORTED.

Describe the solution you'd like

I need a way to tell axios to always use the http adapter. The easiest way to do this is by exposing axios/lib/adapters/http.

Describe alternatives you've considered

No response

Additional context/Screenshots

No response

Activity

  1. WillianAgostini commented on Nov 13, 2022

    @WillianAgostini
    Contributor

    Hi @dysolix

    You can import the correct adapter like this using [email protected]

    axios.get(url, {
      adapter: require('axios/lib/adapters/http'),
    })

    or

    const instance = axios.create({
      adapter: require('axios/lib/adapters/http'),
    })

    With version [email protected] and [email protected] the http module is not being exported;
    Is throwing this exception.

    Uncaught Exception:
    Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/adapters/http' is not defined by "exports" in /home/willian/projets/electron-quick-start/node_modules/axios/package.json
        at new NodeError (node:internal/errors:372:5)
        at throwExportsNotFound (node:internal/modules/esm/resolve:472:9)
        at packageExportsResolve (node:internal/modules/esm/resolve:753:3)
        at resolveExports (node:internal/modules/cjs/loader:489:36)
        at Module._findPath (node:internal/modules/cjs/loader:529:31)
        at Module._resolveFilename (node:internal/modules/cjs/loader:926:27)
        at n._resolveFilename (node:electron/js2c/browser_init:249:1105)
        at Module._load (node:internal/modules/cjs/loader:785:27)
        at c._load (node:electron/js2c/asar_bundle:5:13339)
        at Module.require (node:internal/modules/cjs/loader:1012:19)
    

    I'll create a new Issue to solve this

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