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

global is not defined Angular 6 #1411

Closed
Bartheyrman22 opened this issue Jun 16, 2018 · 16 comments
Closed

global is not defined Angular 6 #1411

Bartheyrman22 opened this issue Jun 16, 2018 · 16 comments

Comments

@Bartheyrman22
Copy link

Using any browser, by just performing a login with this library we get this error:

image

I saw this was already fixed in the main Auth0.js library:
auth0/auth0.js#753

@luisrudge
Copy link
Contributor

it will be fixed in the next release, when we upgrade the auth0-js dependency

@alexDrinkwater
Copy link

@luisrudge Is their an easy work around in the meantime?

@luisrudge
Copy link
Contributor

Use the cdn or see the wordaround

@MichaelBui
Copy link

I'm using:

    "auth0-js": "^9.7.3",
    "auth0-lock": "^11.8.0",

that was just 3,4 days ago but this error's still happening

@luisrudge
Copy link
Contributor

@MichaelBui can you please run npm ls auth0-js and npm ls auth0-lock in your project root?

@MichaelBui
Copy link

Here is the result:

Michaels-MacBook-Pro-4:frontend michaelbui$ npm ls auth0-js
frontend@0.0.1 /Volumes/***/frontend
├── auth0-js@9.7.3 
└─┬ auth0-lock@11.8.0
  └── auth0-js@9.7.3  deduped

Michaels-MacBook-Pro-4:frontend michaelbui$ npm ls auth0-lock
frontend@0.0.1 /Volumes/***/frontend
└── auth0-lock@11.8.0 

Forgot to mention, I'm using Ionic 4 Beta 0.

@luisrudge
Copy link
Contributor

can you paste a stack trace of the issue?

@MichaelBui
Copy link

Here you are:

core.js:1633 ERROR Error: Uncaught (in promise): ReferenceError: global is not defined
ReferenceError: global is not defined
    at Object../node_modules/auth0-lock/lib/utils/cdn_utils.js (cdn_utils.js:13)
    at __webpack_require__ (bootstrap:81)
    at Object../node_modules/auth0-lock/lib/i18n.js (i18n.js:36)
    at __webpack_require__ (bootstrap:81)
    at Object../node_modules/auth0-lock/lib/core/index.js (index.js:78)
    at __webpack_require__ (bootstrap:81)
    at Object../node_modules/auth0-lock/lib/ui/box/chrome.js (chrome.js:29)
    at __webpack_require__ (bootstrap:81)
    at Object../node_modules/auth0-lock/lib/ui/box/container.js (container.js:14)
    at __webpack_require__ (bootstrap:81)
    at Object../node_modules/auth0-lock/lib/utils/cdn_utils.js (cdn_utils.js:13)
    at __webpack_require__ (bootstrap:81)
    at Object../node_modules/auth0-lock/lib/i18n.js (i18n.js:36)
    at __webpack_require__ (bootstrap:81)
    at Object../node_modules/auth0-lock/lib/core/index.js (index.js:78)
    at __webpack_require__ (bootstrap:81)
    at Object../node_modules/auth0-lock/lib/ui/box/chrome.js (chrome.js:29)
    at __webpack_require__ (bootstrap:81)
    at Object../node_modules/auth0-lock/lib/ui/box/container.js (container.js:14)
    at __webpack_require__ (bootstrap:81)
    at resolvePromise (zone.js:814)
    at resolvePromise (zone.js:771)
    at zone.js:873
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421)
    at Object.onInvokeTask (core.js:3751)
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:420)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:188)
    at drainMicroTaskQueue (zone.js:595)

@MichaelBui
Copy link

MichaelBui commented Jul 27, 2018

This is (partial) code of cdn_utils.js in the npm package:

'use strict';

exports.__esModule = true;
exports.load = load;
exports.preload = preload;

var _auth0Js = require('auth0-js');

var _auth0Js2 = _interopRequireDefault(_auth0Js);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

if (!global.Auth0) {
  global.Auth0 = {};
}

var cbs = {};

@MichaelBui
Copy link

And in the source code (https://github.com/auth0/lock/blob/master/src/utils/cdn_utils.js#L3):

import Auth0 from 'auth0-js';

if (!global.Auth0) {
  global.Auth0 = {};
}

const cbs = {};

@luisrudge
Copy link
Contributor

OH yeah, you're right. I mistakenly thought this was only an auth0-js issue, but we have A LOT of global. in our codebase. I don't see us changing that for now, so you'll have to either use our cdn or this workaround:

(window as any).global = window;

@MichaelBui
Copy link

I'm using the Ionic app that is generated by ionic start. Where should I put your code?

@luisrudge
Copy link
Contributor

In the entry file, I guess. index.js or something

@MichaelBui
Copy link

For people who are facing the same problem, I put this in main.ts of Ionic 4 Beta 0:

(window as any).global = window;

Thanks @luisrudge

@luisrudge
Copy link
Contributor

@MichaelBui Thanks for sharing this!

@shanemac10
Copy link

Currently in Ionic 4.1.2

It didn't work in main.ts for me, had to add it to polyfills.ts, based the Issue comment linked below.

Just paste this on the bottom of your app's polyfills.ts...

// BUG FIX: Add global to window, assigning the value of window itself.
// https://github.com/socketio/socket.io-client/issues/1166#issuecomment-386195105
(window as any).global = window;

socketio/socket.io-client#1166 (comment)

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

5 participants