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

SyntaxError: Identifier 'global' has already been declared #153

Closed
johnny-mcfadden-dailypay opened this issue Jul 1, 2024 · 1 comment
Closed

Comments

@johnny-mcfadden-dailypay
Copy link

johnny-mcfadden-dailypay commented Jul 1, 2024

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch socketcluster-client@19.1.2 for the project I'm working on ("expo": "51.0.17" + "react-native": "0.74.2" being the main upgrade drivers that resulted in this issue).

On web, we are running into an issue with global already declared, causing our web bundling to fail.

Screenshot 2024-07-01 at 14 28 46

Here is the diff that solved my problem that I hoped to shared with others.

diff --git a/node_modules/socketcluster-client/lib/ws-browser.js b/node_modules/socketcluster-client/lib/ws-browser.js
index 32e279c..1614e0d 100644
--- a/node_modules/socketcluster-client/lib/ws-browser.js
+++ b/node_modules/socketcluster-client/lib/ws-browser.js
@@ -1,11 +1,11 @@
-let global;
+let globalScope;
 if (typeof WorkerGlobalScope !== 'undefined') {
-  global = self;
+  globalScope = self;
 } else {
-  global = typeof window !== 'undefined' && window || (function() { return this; })();
+  globalScope = typeof window !== 'undefined' && window || (function() { return this; })();
 }
 
-const WebSocket = global.WebSocket || global.MozWebSocket;
+const WebSocket = globalScope.WebSocket || globalScope.MozWebSocket;
 
 /**
  * WebSocket constructor.

This issue body was partially generated by patch-package.

@jondubois
Copy link
Member

@johnny-mcfadden-dailypay Thanks for this report. This suggestion has been implemented and published as socketcluster-client@19.2.2.

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