mikemaccana / whois-json

Whois with results in actual, structured, camelCased JavaScript!
61 stars 34 forks source link

Reference Error log is not defined #36

Open techwithtwin opened 2 weeks ago

techwithtwin commented 2 weeks ago

image

Lissy93 commented 3 days ago

I'm seeing this too (error logs below, for reference)

Stack Trace ``` runtime has escaped from the event loop unexpectedly: event loop error: ReferenceError: log is not defined at https://esm.sh/v135/whois-json@2.0.4/esnext/whois-json.mjs:9:274 at https://esm.sh/v135/whois-json@2.0.4/esnext/whois-json.mjs:8:452 at https://esm.sh/v135/whois-json@2.0.4/esnext/whois-json.mjs:9:550 failed to send request to user worker: event loop error: ReferenceError: log is not defined at https://esm.sh/v135/whois-json@2.0.4/esnext/whois-json.mjs:9:274 at https://esm.sh/v135/whois-json@2.0.4/esnext/whois-json.mjs:8:452 at https://esm.sh/v135/whois-json@2.0.4/esnext/whois-json.mjs:9:550 user worker failed to respond: event loop error: ReferenceError: log is not defined at https://esm.sh/v135/whois-json@2.0.4/esnext/whois-json.mjs:9:274 at https://esm.sh/v135/whois-json@2.0.4/esnext/whois-json.mjs:8:452 at https://esm.sh/v135/whois-json@2.0.4/esnext/whois-json.mjs:9:550 InvalidWorkerResponse: event loop error: ReferenceError: log is not defined at https://esm.sh/v135/whois-json@2.0.4/esnext/whois-json.mjs:9:274 at https://esm.sh/v135/whois-json@2.0.4/esnext/whois-json.mjs:8:452 at https://esm.sh/v135/whois-json@2.0.4/esnext/whois-json.mjs:9:550 at async Promise.allSettled (index 1) at async UserWorker.fetch (ext:sb_user_workers/user_workers.js:73:61) at async Object.handler (file:///root/index.ts:172:14) at async respond (ext:sb_core_main_js/js/http.js:163:14) { name: "InvalidWorkerResponse" } ```

The issue seems to be caused by:

https://github.com/mikemaccana/whois-json/blob/82de25f73fc12703b78e974ac5ea92fae5172a81/index.js#L3

The fix would be to update it to:

- log = console.log.bind(console),
+ const log = (...args) => console.log(...args);

If this project is still maintained, I'd be happy to run some tests and submit a PR? :)


@techwithtwin, are you using a non-node runtime, like Deno? If so, that would explain why you're seeing this, as the method binding technique used here works only in Node.js, because console.log is a build-in function. But this approach will cause issues in any other runtime environment, since it won't be able to handle the bound reference properly.

I'm guessing the original purpose of this is to ensure that console.log is always called with the correct this context (@mikemaccana?). However, in this context I don't think it's necessary, console.log is usually pretty robust without needing to bind its context explicitly, and it just adds confusion to the code, as well as preventing it from working in other runtimes.

Lissy93 commented 3 days ago

In case anyone was looking for a working version, I've re-written this package to resolve this issue, and to make it compatible with newer versions of JS as well as a variety of runtimes.

https://gist.github.com/Lissy93/e33a6b2218f57c51127bbbe7046f5c83

Hope that helps someone :)