Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node-fetch interferes with safe-stable-stringify #51

Open
AndrewThorwall opened this issue Nov 21, 2024 · 0 comments
Open

node-fetch interferes with safe-stable-stringify #51

AndrewThorwall opened this issue Nov 21, 2024 · 0 comments

Comments

@AndrewThorwall
Copy link

Hi,

This is a bit of an odd one, and the issue very may lie somewhere other than this library. But I figured I'd pass this along in case anybody has any ideas.

If I run the following Node.js script (TypeScript with ES module interop enabled):

import stringify from "safe-stable-stringify";
import fetch from "node-fetch";
process.on("warning", warning => {
  console.log("Received a warning event from Node.js", warning.name);
  const w = stringify(warning);
  // Just reference this so that the compiler doesn't filter out the unused import, which I suspect has side effects
  const f = fetch;
});
// Trigger a warning to invoke the above logging
for (let i = 0; i < 200; i++) {
  process.on("warning", () => {});
}

here is the output I get:

(node:172053) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 warning listeners added to [process]. MaxListeners is 10. Use emitter.setMaxListeners() to increase limit
(Use `node --trace-warnings ...` to show where the warning was created)
Received a warning event from Node.js MaxListenersExceededWarning
TypeError: Method get TypedArray.prototype.length called on incompatible receiver [object Object]
    at get length [as length] (<anonymous>)
    at Uint8Array.toJSON (node:buffer:1141:12)
    at stringifySimple (/workspaces/obsidian/node_modules/safe-stable-stringify/index.js:509:25)
    at stringifySimple (/workspaces/obsidian/node_modules/safe-stable-stringify/index.js:572:23)
    at stringifySimple (/workspaces/obsidian/node_modules/safe-stable-stringify/index.js:572:23)
    at stringifySimple (/workspaces/obsidian/node_modules/safe-stable-stringify/index.js:572:23)
    at stringifySimple (/workspaces/obsidian/node_modules/safe-stable-stringify/index.js:536:25)
    at stringifySimple (/workspaces/obsidian/node_modules/safe-stable-stringify/index.js:572:23)
    at stringifySimple (/workspaces/obsidian/node_modules/safe-stable-stringify/index.js:540:23)
    at stringifySimple (/workspaces/obsidian/node_modules/safe-stable-stringify/index.js:572:23)

If I remove any references to node-fetch, the script works as expected:

(node:172353) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 warning listeners added to [process]. MaxListeners is 10. Use emitter.setMaxListeners() to increase limit
(Use `node --trace-warnings ...` to show where the warning was created)
Received a warning event from Node.js MaxListenersExceededWarning

It seems that importing node-fetch is doing something that interferes with safe-stable-stringify.

Versions:

  • safe-stable-stringify: 2.5.0
  • node-fetch: 2.6.7 (unfortunately we are not yet on ESM and can't use v3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant