Auth0.js: global is not defined Angular 6

Created on 4 May 2018  路  16Comments  路  Source: auth0/auth0.js

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

image

Most helpful comment

as temporary workaround for any that reach this page you can add

(window as any).global = window;

in polyfill.ts

All 16 comments

as temporary workaround for any that reach this page you can add

(window as any).global = window;

in polyfill.ts

Thanks for the workaround. At this point, the angular community will have to come with a solution for this problem, since we're hardly the only library using global. This was already discussed in #748. Moving away from using global means a huge refactor in auth0.js and it's not something we'll actively work on in the near future.

More context on the angular change here: https://github.com/angular/angular-cli/issues/9827#issuecomment-369578814

@luisrudge would you be happy with a fix like this in your windows.js

  function getWindow() {
    return global ? global.window : window;
  }

and refactor some code to use getWindow exclusively. I noticed in other places you also use global.window to get the window object.

I can prepare PR in that case.

@fetis I think this is a bigger change than you think, but if you want to go for it, I'll review and test your PR 馃帀

Workaround doesn't workaround for me.

@tinyweasel you don't need workaround anymore. it's fixed since v9.6.1

I just upgraded to Angular 7 and it's happening to me though. What should I update to fix it?

@tinyweasel could you plz provide reproduction code and libs versions plz?

// app/app.js

import Application from '@ember/application';
import Resolver from './resolver';
import loadInitializers from 'ember-load-initializers';
import config from './config/environment';

window.global = window; //add this to your app.

const App = Application.extend({
  modulePrefix: config.modulePrefix,
  podModulePrefix: config.podModulePrefix,
  Resolver
});

loadInitializers(App, config.modulePrefix);

export default App;

i had same issue i just tried "npm install" it shows another error
"Error on Content Security Policy directive"
i was just added (window as any).global = window; in polyfilles.ts
now its working fine.

@jayzhou3 @ram4420 the original issue originates to Angular and it was fixed. If you have an issue with other frameworks plz open another ticket and don't pollute this one.

@jayzhou3 @ram4420 the original issue originates to Angular and it was fixed. If you have an issue with other frameworks plz open another ticket and don't pollute this one.

I see, so it only fix on the angular but it does not fix on Emberjs, Vuejs, Reactjs ... etc...

Thank you

I see, so it only fix on the angular but it does not fix on Emberjs, Vuejs, Reactjs ... etc..

in my opinion, it should, but I don't know your environment and lib versions and can't help you to test it because I'm not familiar with Ember

In my case (Angular 8.1.2 and ionic 4.7.1) not only global was missing but also Bufferand process. I had to add following lines to the end of polyfills.ts:

// auth0 needs this
(window as any).global = window;
// @ts-ignore
window.Buffer = window.Buffer || require('buffer').Buffer;
// @ts-ignore
window.process = window.process || { version: "" }

UPDATE IMPORTANT: My mistake. I was using the auth0 ionic 3 example as basis to add the needed changes to my project (which is ionic 4). After doing everything like shown in the auth0 ionic 4 example it worked without modifying polyfills.ts. I leave this comment here though, in case somebody else makes this silly mistake.

Workaround for me is to add bundle to index.html
<script src="https://cdn.auth0.com/js/lock/11.14.1/lock.min.js"></script>
instead ofimport 'auth0-lock'in .ts file
Few things are weird:

  1. minified version from CDN working OK but imported one from node modules is not working
  2. 'auth0-lock' from npm does not contain build(minified) version.

@luisrudge is it possible to include compiled version to npm package?

Was this page helpful?
0 / 5 - 0 ratings