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

Reference Error log is not defined #36

Open
techwithtwin opened this issue Oct 3, 2024 · 2 comments
Open

Reference Error log is not defined #36

techwithtwin opened this issue Oct 3, 2024 · 2 comments

Comments

@techwithtwin
Copy link

image

@Lissy93
Copy link

Lissy93 commented Oct 19, 2024

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/[email protected]/esnext/whois-json.mjs:9:274
    at https://esm.sh/v135/[email protected]/esnext/whois-json.mjs:8:452
    at https://esm.sh/v135/[email protected]/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/[email protected]/esnext/whois-json.mjs:9:274
    at https://esm.sh/v135/[email protected]/esnext/whois-json.mjs:8:452
    at https://esm.sh/v135/[email protected]/esnext/whois-json.mjs:9:550
user worker failed to respond: event loop error: ReferenceError: log is not defined
    at https://esm.sh/v135/[email protected]/esnext/whois-json.mjs:9:274
    at https://esm.sh/v135/[email protected]/esnext/whois-json.mjs:8:452
    at https://esm.sh/v135/[email protected]/esnext/whois-json.mjs:9:550
InvalidWorkerResponse: event loop error: ReferenceError: log is not defined
    at https://esm.sh/v135/[email protected]/esnext/whois-json.mjs:9:274
    at https://esm.sh/v135/[email protected]/esnext/whois-json.mjs:8:452
    at https://esm.sh/v135/[email protected]/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:

log = console.log.bind(console),

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
Copy link

Lissy93 commented Oct 19, 2024

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 :)

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

2 participants