securesecrets / shadejs

SDK for integrating with Shade contracts
https://shadejs.dev
7 stars 1 forks source link

shadejs overwrites `fetch` global #107

Closed blake-regalia closed 4 months ago

blake-regalia commented 4 months ago

Describe the bug We seem to be encountering an issue with node.js due to shadejs build that assume the environment is the browser and is forcing node polyfills, overwriting the fetch global and leading to this error:

/node_modules/@shadeprotocol/shadejs/dist/index.js:10363
              var H = new XMLHttpRequest();
                      ^

ReferenceError: XMLHttpRequest is not defined
    at /node_modules/@shadeprotocol/shadejs/dist/index.js:10363:23
    at new Promise (<anonymous>)
    at A (/node_modules/@shadeprotocol/shadejs/dist/index.js:10359:20)

Inspecting fetch reveals the polyfill:

> fetch
<ref *1> [Function: A] {
  ponyfill: true,
  default: [Circular *1],
  fetch: [Circular *1],
  Headers: [Function: u],
  Request: [Function: T],
  Response: [Function: I] {
    error: [Function (anonymous)],
    redirect: [Function (anonymous)]
  }
}

To Reproduce Try importing the ESM in node.js and attempt to perform fetch().

Expected behavior Don't overwrite globals in node.js environment. Should be exporting ESM and use the "exports" package.json feature.

AustinWoetzel commented 4 months ago

We are troubleshooting a similar problem with node.js environment right now, hopefully have a solution soon.

AustinWoetzel commented 4 months ago

Did versions 1.1.2 and earlier work for you, or do you see the same issue there?

AustinWoetzel commented 4 months ago

Please let us know if the above fix does not resolve your issues. It should as we removed the polyfill.