Skip to content

Commit da69651

Browse files
Fix missing XMLHttpRequest on node environments
1 parent 933285a commit da69651

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

package-lock.json

+10-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"console": "^0.7.2",
3232
"decimal.js": "^10.4.3",
3333
"google-protobuf": "^3.20.3",
34-
"grpc-web": "^1.4.2"
34+
"grpc-web": "^1.4.2",
35+
"node-xmlhttprequest": "^1.0.6"
3536
},
3637
"devDependencies": {
3738
"@babel/core": "^7.21.0",
@@ -48,7 +49,6 @@
4849
"eslint-plugin-jsx-a11y": "^6.7.1",
4950
"jest": "^29.7.0",
5051
"monero-ts": "^0.11.1",
51-
"node-xmlhttprequest": "^1.0.6",
5252
"ts-jest": "^29.2.5",
5353
"ts-jest-resolver": "^2.0.1",
5454
"typedoc": "^0.23.26",

src/index.ts

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
try {
2+
new XMLHttpRequest();
3+
}
4+
catch {
5+
const xhr = require('node-xmlhttprequest');
6+
7+
//@ts-ignore
8+
global.ProgressEvent = xhr.ProgressEvent;
9+
//@ts-ignore
10+
global.XMLHttpRequestEventTarget = xhr.XMLHttpRequestEventTarget;
11+
//@ts-ignore
12+
global.XMLHttpRequestUpload = xhr.XMLHttpRequestUpload;
13+
//@ts-ignore
14+
global.XMLHttpRequest = xhr.XMLHttpRequest;
15+
}
16+
117
import HavenoClient from "./HavenoClient";
218
import HavenoError from "./types/HavenoError";
319
import HavenoUtils from "./utils/HavenoUtils";

0 commit comments

Comments
 (0)