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

XMLHttpRequest is not defined in Netlify Functions #370

Open
pankajpatel opened this issue Feb 16, 2021 · 3 comments
Open

XMLHttpRequest is not defined in Netlify Functions #370

pankajpatel opened this issue Feb 16, 2021 · 3 comments
Labels
bug Something isn't working

Comments

@pankajpatel
Copy link

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
@nrdcp
Copy link

nrdcp commented Aug 25, 2021

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

@gaetandezeiraud
Copy link

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

Any idea?

@pankajpatel
Copy link
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.

@daniellockyer daniellockyer added the bug Something isn't working label Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants