bugsnag-js
                                
                                 bugsnag-js copied to clipboard
                                
                                    bugsnag-js copied to clipboard
                            
                            
                            
                        @bugsnag/electron does not work with Windows 7 and Electron 19+
Describe the bug
The os.hostname() node API throws on Windows 7 with Electron 19+ with a uv_os_gethostname returned ENOSYS error. This API is used in @bugnsag/cuid/lib/fingerprint.js, and causes a crash on startup.
- Libuv bug: https://github.com/libuv/libuv/issues/3260
- Node bug: https://github.com/nodejs/node/issues/41297
- Electron bug: https://github.com/electron/electron/issues/34404
libuv and node don't support Windows 7, so those projects seem very unlikely address this. Electron claims support for Windows 7 but it's unclear if they will address this or not (currently looking like not).
I was able to address this in my project with this patch:
diff --git a/node_modules/@bugsnag/cuid/lib/fingerprint.js b/node_modules/@bugsnag/cuid/lib/fingerprint.js
index 5f9f765..ab1a3a7 100644
--- a/node_modules/@bugsnag/cuid/lib/fingerprint.js
+++ b/node_modules/@bugsnag/cuid/lib/fingerprint.js
@@ -1,9 +1,17 @@
 var pad = require('./pad.js');
 
+function tryGetHostname() {
+  try {
+    return os.hostname();
+  } catch (err) {
+    return '';
+  }
+}
+
 var os = require('os'),
     padding = 2,
     pid = pad(process.pid.toString(36), padding),
-    hostname = os.hostname(),
+    hostname = tryGetHostname(),
     length = hostname.length,
     hostId = pad(hostname
       .split('')
Hi @jeremyspiegel - thanks for raising this and sharing your solution. We're going to investigate and look at releasing a fix. We'll make sure we keep you updated on this thread 👍
I have made a test on Electron Fiddle: https://gist.github.com/NemoAlex/431a61e8464ee6d606f3a02868c66017 Electron 19 Binary uses Node.js 16.14.2, maybe version before 16.14.0(libuv 1.42.0) was fine. Such as Electron 18 uses Node.js 16.13.2, can pass the test. https://github.com/nodejs/node/blob/main/doc/changelogs/CHANGELOG_V16.md
I've filled in separate issue #1799 before finding this one, it is directly related.
I will close it in favor of this one but want to mention it due to the reference to another possible place where the affected function is being called.
@luke-belton Hello! Any news about this? Our app started crashing on Windows 7 because of this. I will try disabling Bugsnag to see if it will solve the problem for now.
Eu fiz um teste no Electron Fiddle: https://gist.github.com/NemoAlex/431a61e8464ee6d606f3a02868c66017 Electron 19 Binary usa Node.js 16.14.2, talvez a versão anterior a 16.14.0 (libuv 1.42.0) estivesse bem. Como o Electron 18 usa Node.js 16.13.2, pode passar no teste. https://github.com/nodejs/node/blob/main/doc/changelogs/CHANGELOG_V16.md
I was looking into the problem with electron in general and downgrading to electron in version 18 fixed the error! Thx very much!
@Tulipesz The reason of the issue is the use of cuid library in Bugsnag. I've already sent PR https://github.com/ericelliott/cuid/pull/264 to the original library, but it is not merged yet.
Bugsnag maintains its own fork: https://github.com/bugsnag/cuid, so hopefully, they will update it too. @luke-belton Maybe you will consider porting proposed change to your fork? It was approved in general by the library author.
In meantime, I've solved the issue for myself by using patch-package
Looks like this was fixed in Electron via https://github.com/electron/electron/issues/35219.
Just to let you know we have now released v3.0.2 of bugsnag/cuid which includes the changes mentioned above, so this issue should now be fixed.