TryGhost / SDK

Tools for working with Ghost's APIs
MIT License
116 stars 76 forks source link

XMLHttpRequest is not defined in Netlify Functions #370

Open pankajpatel opened 3 years ago

pankajpatel commented 3 years ago

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:

nrdcp commented 3 years ago

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 commented 2 years ago

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

Any idea?

pankajpatel commented 2 years ago

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.