amplitude / Amplitude-JavaScript

JavaScript SDK for Amplitude
MIT License
315 stars 132 forks source link

[Amplitude] ReferenceError: XMLHttpRequest is not defined #561

Closed detailswes closed 1 year ago

detailswes commented 1 year ago

version : "amplitude-js": "^8.21.1", while starting app I am getting [Amplitude] amplitude-js will not work in a non-browser environment. If you are planning to add Amplitude to a node environment, please use @amplitude/node.
I am using next js please tell me the solution

kevinpagtakhan commented 1 year ago

Hi @detailswes, to use amplitude-js in Next.js, you'll have to make sure that logEvent call is only invoked in the browser environment, and not in the node environment. The node environment does not support XMLHttpRequest, which is the default http client that amplitude-js uses.