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

ReferenceError: Can't find variable: global #10824

Closed
AnasSahel opened this issue May 12, 2018 · 7 comments
Closed

ReferenceError: Can't find variable: global #10824

AnasSahel opened this issue May 12, 2018 · 7 comments

Comments

@AnasSahel
Copy link

Versions

Angular CLI: 6.0.1
Node: 8.11.1
OS: darwin x64
Angular: 6.0.1
... animations, cli, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.6.1
@angular-devkit/build-angular     0.6.1
@angular-devkit/build-optimizer   0.6.1
@angular-devkit/core              0.6.1
@angular-devkit/schematics        0.6.1
@ngtools/webpack                  6.0.1
@schematics/angular               0.6.1
@schematics/update                0.6.1
rxjs                              6.1.0
typescript                        2.7.2
webpack                           4.6.0

node version: v8.11.1
npm version: 6.0.0

macOS Sierra

Repro steps

  • Install socket.io-client
  • in app.component.ts, import socket.io-client as io, and do io('...')

Observed behavior

We get this error in the browser: ReferenceError: Can't find variable: global

Desired behavior

No error

Mention any other details that might be useful (optional)

A workaround fixed the issue:

  • Workaround 1: add (windows as any).global = window to polyfills.ts
  • Workaround 2: add window.global = window to index.html
@FabianScheidt
Copy link

+1
I have the same issue. The workaround fixes the issue though...

@PhilippeCorreges
Copy link

Hello Everyone.
Just facing the issue... I did not really understood the workaround. Where to set the variables please?
I thank you in advance for your help.

@FabianScheidt
Copy link

Well, the issue is that the library tries to find a variable called global which is expected to contain all existing global variables (which usually window does). But this variable is for some reasons undefined so you need to define it on your own by either adding it in the index.html file by adding a script tag to the head:

<script type="text/javascript">
window.global = window;
</script>

Or you do the same thing in polyfills.ts with some decorations to make the Typescript compiler happy:

(windows as any).global = window;

@PhilippeCorreges
Copy link

Thanks. I just modified my index.html.
Works fine.

@Lugdunumn
Copy link

I have the same issue caused by intl polyfill. Workaround 2 worked fine.

@ngbot ngbot bot added this to the needsTriage milestone Jan 24, 2019
@filipesilva
Copy link
Contributor

In Angular CLI 6 we did remove the node global and others. You can read more about this in #9827 (comment).

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants