Skip to content

XMLHttpRequest is not defined in Netlify Functions #370

Open

Description

@pankajpatel

Issue Summary

XMLHttpRequest is not defined in Netlify Functions

To Reproduce

  1. Try to fetch content via Content API JS SDK in netlify function

I think @tryghost/content-api uses axios to send AJAX requests. Axios depends heavily on XMLHttpRequest for its functioning.

Possible alternatives can be https://github.com/developit/redaxios

Technical details:

  • Ghost Version: 3.41.4
  • Node Version: 12.20.1
  • Browser/OS: Irrelevant
  • Database: mysql

Activity

  1. nrdcp commented on Aug 25, 2021

    @nrdcp

    Looks like the issue is linked to browser: true rollup config option. This will result in axios dependency to be built based on assumption it is used in the browser only - with xhr always used as the adaptor

  2. gaetandezeiraud commented on Jun 23, 2022

    @gaetandezeiraud

    I have the same issue with ElectronJS. On the main (nodejs) thread.
    And axios is a dependency of the project.

    Any idea?

  3. pankajpatel commented on Jun 23, 2022

    @pankajpatel
    Author

    You can maybe alias the axios module imports to redaxios in your bundler.

    For my project, I changed the way I was using the content API to only run on the browser.

  4. SupremeTechnopriest commented on Dec 3, 2024

    @SupremeTechnopriest

    Why Axios?! Its such a horrible abstraction. Please, just use fetch. Its 2024.

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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions