es-shims / es5-shim

ECMAScript 5 compatibility shims for legacy (and modern) JavaScript engines
MIT License
7.12k stars 895 forks source link

Check for module's existence instead of exports #455

Closed MelkorNemesis closed 4 years ago

MelkorNemesis commented 6 years ago

The library should be checking for module existence instead of exports existence. It has happened to us that in the browser for whatever reason exports was pointing to Window and the module check failed on Module is not defined on line 25 in this file. Also it doesn't make sense to check for variable A and then writing to variable B (I know they're aliases in Node, but that's not the case in browser).

borisvalo commented 6 years ago

+1

ljharb commented 6 years ago

This is a standard UMD that has worked, unchanged, for the better part of a decade. Are you using es5-shim directly, or as part of a bundler? If directly, what was setting the global exports variable? That’s likely to break a good many libraries you might be using.

Separately, This isn’t the right fix, because module = Window would break your code too, would it not?