ollama-js icon indicating copy to clipboard operation
ollama-js copied to clipboard

ReferenceError: XMLHttpRequest is not defined

Open liugezhou opened this issue 1 year ago • 1 comments

image

When i run node demo.js,and then:

/User/xxx/Demo/aidemo/node_modules/whatwg-fetch/dist/fetch.umd.js:540 var xhr = new XMLHttpRequest(); ^

ReferenceError: XMLHttpRequest is not defined

liugezhou avatar May 09 '24 06:05 liugezhou

I had the same error on Node.js v17. Tried lots of things then accidently found out that it's working perfect with Node.js v18.

ozgrozer avatar May 12 '24 19:05 ozgrozer

Note for people stuck to nodejs < 18

npm install xhr2
global.XMLHttpRequest = require('xhr2');

skeetmtp avatar Jul 26 '24 09:07 skeetmtp

Note for people stuck to nodejs < 18

npm install xhr2
global.XMLHttpRequest = require('xhr2');

This worked for me, although as soon as I fixed it I realized I'd set that dockerfile to node14 for some reason (smh).

stephcurt avatar Jul 29 '24 00:07 stephcurt

is the supposed to be fixed? xhr2 global patch is not convenient

cool-firer avatar Aug 02 '24 09:08 cool-firer