Skip to content

Commit

Permalink
Fix missing XMLHttpRequest on node environments
Browse files Browse the repository at this point in the history
  • Loading branch information
everoddandeven committed Dec 27, 2024
1 parent 933285a commit da69651
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
24 changes: 10 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"console": "^0.7.2",
"decimal.js": "^10.4.3",
"google-protobuf": "^3.20.3",
"grpc-web": "^1.4.2"
"grpc-web": "^1.4.2",
"node-xmlhttprequest": "^1.0.6"
},
"devDependencies": {
"@babel/core": "^7.21.0",
Expand All @@ -48,7 +49,6 @@
"eslint-plugin-jsx-a11y": "^6.7.1",
"jest": "^29.7.0",
"monero-ts": "^0.11.1",
"node-xmlhttprequest": "^1.0.6",
"ts-jest": "^29.2.5",
"ts-jest-resolver": "^2.0.1",
"typedoc": "^0.23.26",
Expand Down
16 changes: 16 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
try {
new XMLHttpRequest();
}
catch {
const xhr = require('node-xmlhttprequest');

//@ts-ignore
global.ProgressEvent = xhr.ProgressEvent;
//@ts-ignore
global.XMLHttpRequestEventTarget = xhr.XMLHttpRequestEventTarget;
//@ts-ignore
global.XMLHttpRequestUpload = xhr.XMLHttpRequestUpload;
//@ts-ignore
global.XMLHttpRequest = xhr.XMLHttpRequest;
}

import HavenoClient from "./HavenoClient";
import HavenoError from "./types/HavenoError";
import HavenoUtils from "./utils/HavenoUtils";
Expand Down

0 comments on commit da69651

Please sign in to comment.