ng2-dragula icon indicating copy to clipboard operation
ng2-dragula copied to clipboard

Uncaught ReferenceError: global is not defined

Open Mathem8tic opened this issue 6 years ago • 26 comments

Angular 6.0.0-rc.3 and Angular-CLI 6.0.0-rc.2. Error in browser console. Will try and figure out solution and report back...

Mathem8tic avatar Apr 09 '18 17:04 Mathem8tic

It happens with @angular 6.0.0-rc.3 and @angular/cli 6.0.0-rc.3 too.

julianobrasil avatar Apr 11 '18 03:04 julianobrasil

In fact it fails with any versions combination newer than @angular 6.0.0-rc.0 + @angular/cli 1.7.4

It's working with the following combinations: @angular 6.0.0-rc.0 + @angular/cli 1.7.4 @angular 6.0.0-rc.4 + @angular/cli 1.7.4

julianobrasil avatar Apr 11 '18 13:04 julianobrasil

This is probably the cause: https://github.com/angular/angular-cli/issues/9827#issuecomment-369578814

julianobrasil avatar Apr 12 '18 21:04 julianobrasil

Anyone have any luck on this?

plantsmiles avatar Apr 20 '18 21:04 plantsmiles

Any update on this?

jvanhall avatar Apr 30 '18 19:04 jvanhall

I was able to work around this for now by adding an entry for dragula to the paths in my tsconfig.json

"paths": {
      "dragula": ["../node_modules/dragula/dist/dragula.min.js"]
    }

rrajewski avatar Apr 30 '18 20:04 rrajewski

@rrajewski, I owe you a beer!

BTW, I put it on tsconfig.app.json (inside /src directory)

julianobrasil avatar May 01 '18 00:05 julianobrasil

You can add (window as any).global = window; in polyfills.ts

lukica88 avatar May 04 '18 12:05 lukica88

You can add (window as any).global = window; in polyfills.ts worked for me. thanks

geelus avatar May 06 '18 11:05 geelus

You can add (window as any).global = window; in polyfills.ts

Worked like charm. Thanks!

roopeshchinnakampalli avatar May 11 '18 18:05 roopeshchinnakampalli

The solution is just a workaround... Can this be solved properly? https://github.com/angular/angular-cli/issues/9827#issuecomment-369578814

Gerros avatar May 18 '18 12:05 Gerros

<script>
var global = global || window;
var Buffer = Buffer || [];
var process = process || {
  env: { DEBUG: undefined },
  version: []
};
i added this to index.html and that sove the problem

amanymh avatar May 28 '18 21:05 amanymh

@Gerros unfortunately the fix will be just to integrate the workaround. Usually one would just send issues upstream to dragula (code search on both repos reveals no use of global here), but that project has not been touched in a year and I don’t think the original owner still looks at it (calling @bevacqua?). It will have to be @lukica88’s solution but in one of our source files (any one will do) with a link to this issue in a comment. (I can’t push new versions but @valorkin can.)

cormacrelf avatar Jun 11 '18 00:06 cormacrelf

@cormacrelf I can give you push access and could help to set up publish from CI (like in ngx bootstrap) Drop me a note if you are interested in maintaining ng2-dragula :)

Plus I can ask @bevacqua to do the same with dragula :)

valorkin avatar Jun 11 '18 13:06 valorkin

I already have push access. I am supposedly a maintainer. CI publish would make things a lot easier.

(Side note: I have been a bit busy maintaining my own drag and drop library. It’s not like you can really have a conflict of interest at this scale, but all the free time I have left over for drag and drop libraries is going there. I also haven’t used this in live code in almost a year. If anyone else is making heavy use of ng2-dragula, please become a maintainer too.)

On 11 Jun 2018, at 23:28, Dmitriy Shekhovtsov [email protected] wrote:

@cormacrelf I can give you push access and could help to set up publish from CI (like in ngx bootstrap) Drop me a note if you are interested in maintaining ng2-dragula :)

Plus I can ask @bevacqua to do the same with dragula :)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

cormacrelf avatar Jun 11 '18 18:06 cormacrelf

Also @valorkin, last publish was 1.5.0 from #636, but you don't appear to have pushed the commit changing the version number. Was there anything else you didn't push, or can just bump the version past 1.5.0 without losing anything? Ref #747 as well.

cormacrelf avatar Jun 21 '18 02:06 cormacrelf

adding this line in to pollyfills.ts fixed my problem if u r using angular 6

(window as any).global = window;

vikbi avatar Jul 06 '18 12:07 vikbi

Actually, this can't be fixed in ng2-dragula. Seriously.

It would appear dragula gets loaded first, and tries to use window.global. So any polyfilling from inside the lib is too late. To fix it, you'd need to summon @bevacqua from wherever he's gone (other projects, apparently), or maintain a fork. I'm not going to maintain a fork.

I'm leaving this issue open so people can find it, and adding a note to the docs in lieu of actually solving it.

cormacrelf avatar Jul 17 '18 21:07 cormacrelf

Ref https://github.com/bevacqua/dragula/pull/534

cormacrelf avatar Jul 18 '18 13:07 cormacrelf

adding this line in to pollyfills.ts fixed my problem if u r using angular 6

(window as any).global = window;

mhadji avatar Aug 06 '18 05:08 mhadji

Thanks @mhadji, there are a couple quick fixes for this listed above similar to what you have suggested. I think this issue has morphed into a bigger conversation over time. I was able to get things working with something similar to your suggestion.

Mathem8tic avatar Aug 06 '18 05:08 Mathem8tic

I'm leaving this issue open so people can find it, and adding a note to the docs in lieu of actually solving it.

Guys. I’m leaving it open. Until the polyfill is no longer necessary.

cormacrelf avatar Aug 06 '18 06:08 cormacrelf

Caution, I installed ng2-dragula and got this error, so I uninstalled but the error remained... Good I pushed my code so I could reset my branch.

Hypenate avatar Aug 22 '18 13:08 Hypenate

add this line in polyfills.ts

(window as any).global = window;

alaanaeim125 avatar Feb 18 '21 12:02 alaanaeim125

Any update on this? I am still getting this after upgrading to Angular 15 and I have the (window as any).global = window; line in polyfills.ts

exf6514 avatar Mar 16 '23 16:03 exf6514

add this line in AppComponent constructor solved the problem in angular 16 window['global'] = window;

pparce avatar Sep 27 '23 06:09 pparce