You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: for support questions, please use one of these channels: stackoverflow or slack
You want to:
- [x] report a *bug*
- [ ] request a *feature*
Current behaviour
socket.io-client doesn't work with @angular/cli@1.5.0-rc.3 because of a dependency on node.js' global var
(seems to come from has-binary2@1.0.2, but I can't find who maintains that versions)
Steps to reproduce (if the current behaviour is a bug)
Reacted by Ricardo Varanda, Kewin Brandsma, Damian Galetto, Manish Lakhara, Lukas, André Fiedler, Reunan Le noc, Danil Roshko, Fabian Wiles, Yatit Thakker and 18 more
A workaround until Angular CLI maybe fixes it or make it possible to override the node command, then you can add the socket.io-client slim file in the paths section of the tsconfig.app.json
Reacted by Vincent Stakenburg, Darren Mothersele, Danail Videv, PeS82, Thomas Linford, lpcfs, Patrick Burrows, Renan Rodrigues Moraes, Cameron Hudson, Mohamed El-Far and 6 more
"[this] just generally make for a situation where browser code that shouldn't work at all works only when built in with very specific tooling. This is not a good situation. "
but it's not working in Angular 6RC5, I still get the error:
is-buffer.js:4 Uncaught ReferenceError: global is not defined at Object../node_modules/socket.io-client/node_modules/socket.io-parser/is-buffer.js (is-buffer.js:4) at __webpack_require__ (bootstrap:74) at Object../node_modules/socket.io-client/node_modules/socket.io-parser/binary.js (binary.js:8) at __webpack_require__ (bootstrap:74) at Object../node_modules/socket.io-client/node_modules/socket.io-parser/index.js (index.js:8) at __webpack_require__ (bootstrap:74) at Object../node_modules/socket.io-client/lib/index.js (index.js:7) at __webpack_require__ (bootstrap:74) at Object../src/app/_services/websocket.service.ts (log.service.ts:5) at __webpack_require__ (bootstrap:74)
Reacted by lpcfs, DMW007, Renan Rodrigues Moraes, Nguyen Thanh Duong and Fan Jin
adding the following polyfills.ts should work in Angular@6:
// Add global to window, assigning the value of window itself.(windowasany).global=window;
In any case, this issue should not be resolved IMO, socket.io-client should either remove the implicit dependency on global, or document that a polyfill is needed (by anyone using the pre-bundled sources, not just Angular users)
(BTW where are the sources for latest has-binary2@1.0.2? maybe I could help)
Reacted by Danil Roshko, Darren Mothersele, Pablo Reinoso, JULIAN, michaelb-01, Shem Leong, Haroen Viaene, Madhusudhan, Michael Weber, palucdev and 126 more
Reacted by Renan Rodrigues Moraes, Marco Lackovic, Fan Jin, lauramerino, David Saleh, Lucas Frecia, Ulrich Dohou, blackpeakpools, Diego Restrepo Mesa, Fernando Hernandez and 4 more
Reacted by Pablo Reinoso, Márcio Reis, Tu Chu, Yatit Thakker, MadMango, Patrick Burrows, Renan Rodrigues Moraes, Carsten, edward sharp, Frederic and 29 more
Reacted by Renan Rodrigues Moraes, Marco Lackovic, q0xz, Christian Hardy, lauramerino, David Saleh, Manuel Roque, Carina Landerer, adriangradinar, Abdulrahman Alaa Eldin and 28 more
Reacted by Matías Gutierrez, Marco De la Rosa and guanyuhoujeff
@darrenmothersele don't think there is exactly one "better". Adding 'global' may have side effects for other libs while adding the 'slim' file may have a negative effect on bundle size (not necessarily)
I tried both solutions and with a current angular 6.0.0 project and none works. I added the paths entry to the tsconfig.app.json and the entry to polyfills.ts but still getting the same error in chrome.
In my situation, it seems 2.2.0 depends on "engine.io-client": "~3.3.1", which depends on "engine.io-parser": "~2.1.1". However the engine.io-parser on my system seems to be 2.1.2 which still contains references to the 'global' variable. It seems this has been fixed in 2.1.3, but the npm i seems to be pulling 2.1.2
I've same problem with Jest + React + Typescript, and couldn't fix it setting (window as any).global = window. I tried putting the code in a polyfills.ts file as well,
@eldem and others. I'm closing this as this thread became too a generic mix of possibly unrelated issues. If anybody sees a problem relating to global and socket.io-client, please open a new issue with reproduction instructions, errors shown in console, versions used, etc.,.
I closed this issue as it started to diverge to many different issues related to global usage. This started as a specific use case and was not about removing 'global' in general. I suggest checking if your issue exists elsewhere and opening a new one if needed.
Activity
[-]global is not defined[/-][+][bug] global is not defined[/+]RicardoVaranda commentedon Oct 24, 2017
Also facing this issue currently
darrachequesne commentedon Mar 10, 2018
Since angular/angular-cli#8160 is now resolved, can we close this issue? Thanks!
KevinGruber commentedon Mar 11, 2018
I don't think so, because in the angular/cli > 6 they permanently removed global.
Can you please start looking intoit again? angular/angular-cli#9827
BR,
Kevin
mikkeldamm commentedon Apr 6, 2018
A workaround until Angular CLI maybe fixes it or make it possible to override the node command, then you can add the socket.io-client slim file in the paths section of the
tsconfig.app.jsonamitport commentedon Apr 8, 2018
Even if it does currently work, according to angular/angular-cli#9827 (comment), this will be an issue in
Angular@6:"[this] just generally make for a situation where browser code that shouldn't work at all works only when built in with very specific tooling. This is not a good situation. "
ngervasi commentedon Apr 23, 2018
I confirm it's broken in Angular 6 RC5. Does anybody know a workaround?
mikkeldamm commentedon Apr 23, 2018
@ngervasi we have done it by doing like i commented here: #1166 (comment)
ngervasi commentedon Apr 23, 2018
I tried:
{ "extends": "../tsconfig.json", "compilerOptions": { "outDir": "../out-tsc/app", "module": "es2015", "baseUrl": "", "types": [] }, "exclude": [ "test.ts", "**/*.spec.ts" ], "paths": { "socket.io-client": ["../node_modules/socket.io-client/dist/socket.io.slim.js"] } }but it's not working in Angular 6RC5, I still get the error:
is-buffer.js:4 Uncaught ReferenceError: global is not defined at Object../node_modules/socket.io-client/node_modules/socket.io-parser/is-buffer.js (is-buffer.js:4) at __webpack_require__ (bootstrap:74) at Object../node_modules/socket.io-client/node_modules/socket.io-parser/binary.js (binary.js:8) at __webpack_require__ (bootstrap:74) at Object../node_modules/socket.io-client/node_modules/socket.io-parser/index.js (index.js:8) at __webpack_require__ (bootstrap:74) at Object../node_modules/socket.io-client/lib/index.js (index.js:7) at __webpack_require__ (bootstrap:74) at Object../src/app/_services/websocket.service.ts (log.service.ts:5) at __webpack_require__ (bootstrap:74)amitport commentedon May 3, 2018
According to angular/angular-cli#8160 (comment):
adding the following
polyfills.tsshould work inAngular@6:In any case, this issue should not be resolved IMO, socket.io-client should either remove the implicit dependency on
global, or document that a polyfill is needed (by anyone using the pre-bundled sources, not just Angular users)(BTW where are the sources for latest
has-binary2@1.0.2? maybe I could help)darrenmothersele commentedon May 4, 2018
Which is the better fix? #1166 (comment) (adding to paths in tsconfig) or #1166 (comment) (assigning to global)?
Both options worked for me in Angular v6 project generated with Angular CLI.
darrachequesne commentedon May 4, 2018
@amitport the sources for the
has-binary2package are here: https://github.com/darrachequesne/has-binaryThough I'm afraid it's not the sole occurence.
amitport commentedon May 4, 2018
@darrenmothersele don't think there is exactly one "better". Adding 'global' may have side effects for other libs while adding the 'slim' file may have a negative effect on bundle size (not necessarily)
@darrachequesne added a PR darrachequesne/has-binary#4 (it's a start :))
gentle9 commentedon May 5, 2018
I tried both solutions and with a current angular 6.0.0 project and none works. I added the paths entry to the tsconfig.app.json and the entry to polyfills.ts but still getting the same error in chrome.
matheusdavidson commentedon May 8, 2018
same here, the tsconfig solution does not work on ng cli 6
37 remaining items
Sliverb commentedon Jan 25, 2019
In my situation, it seems 2.2.0 depends on "engine.io-client": "~3.3.1", which depends on "engine.io-parser": "~2.1.1". However the engine.io-parser on my system seems to be 2.1.2 which still contains references to the 'global' variable. It seems this has been fixed in 2.1.3, but the npm i seems to be pulling 2.1.2
If i had to make a guess, it seems it might be reverting back to 2.1.2 because the last build for 2.1.3 failed
https://travis-ci.org/socketio/engine.io-parser
Aside from that, i cant figure out why it keeps pulling the older version for me
eldem commentedon Feb 21, 2019
I've same problem with Jest + React + Typescript, and couldn't fix it setting
(window as any).global = window. I tried putting the code in apolyfills.tsfile as well,and also using Jest's defineProperty method, but still no luck.
Anyone able to solve this for Jest, or know how I can make this work? @amitport any idea?
Thanks,
amitport commentedon Feb 21, 2019
@eldem and others. I'm closing this as this thread became too a generic mix of possibly unrelated issues. If anybody sees a problem relating to global and socket.io-client, please open a new issue with reproduction instructions, errors shown in console, versions used, etc.,.
dovk commentedon Mar 1, 2019
Working with Ionic4/Angular7 - installing 2.1.1 and adding
(window as any).global = windowin \src\polyfills.ts worked - Thank you!eldem commentedon Mar 1, 2019
For my question above: Babel was causing the error while transforming the socket.io file. Adding it in the transformIgnore worked for me.
yoann-dh commentedon May 30, 2019
@amitport methode work perfectly
[fix] Remove any reference to the `global` variable
[fix] Remove any reference to the `global` variable
[chore] Update to blob@0.0.5 (avoid reference to 'global') (#107)
mohamedmezlini commentedon Jun 5, 2021
the polyfills.ts solution works for me
(window as any).global = window
#Angular_10
[fix] Remove any reference to the `global` variable
locknono commentedon Feb 7, 2022
@amitport So which version of socket.io-client could fix this problem? It seems that it does not work even after upgrading to version 2.3.0.
socket.io-client@2.3.0 still depends on engine.io-client@3.4.4, which references 'global', so it's getting the same error.
amitport commentedon Feb 7, 2022
#1166 (comment)
I closed this issue as it started to diverge to many different issues related to global usage. This started as a specific use case and was not about removing 'global' in general. I suggest checking if your issue exists elsewhere and opening a new one if needed.
locknono commentedon Feb 8, 2022
I found it was actually an issue with vite and yarn pnp, instead of a sheer socket.io-client problem.
See vitejs/vite#1979