Don't create a window.Hammer global when in CommonJS
See original GitHub issueIn hammer.js
:
// this prevents errors when Hammer is loaded in the presence of an AMD
// style loader but by script tag, not by the loader.
var freeGlobal = (typeof window !== 'undefined' ? window : (typeof self !== 'undefined' ? self : {})); // jshint ignore:line
freeGlobal.Hammer = Hammer;
Not sure what such a code wants to prevent, but the fact is that it’s polluting the global namespace (window
) even when CommonJS or AMD is being used.
It shouldn’t.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:15 (6 by maintainers)
Top Results From Across the Web
Dependency on 'hammerjs'. CommonJS or AMD ...
Apparently, it seems you can import hammer.js from platform browser in this way: import { HammerModule} from '@angular/platform-browser'; ...
Read more >How to solve "window is not defined" errors in React and Next.js
Because in the Node.js world, window is not defined, window is only available in browsers. There are three ways to solve that: 1....
Read more >Understanding (all) JavaScript module formats and tools
When you build an application with JavaScript, you always want to ... Exported module is also a global variable(property of window object) ...
Read more >CommonJS Modules in Titanium
There shall not be ANY global variables in a Titanium application shared across all modules. Any data a module or any objects exposed...
Read more >Announcing TypeScript 4.7 Beta - Microsoft Developer Blogs
Node.js allows ES modules to import CommonJS modules as if they were ... make code less portable on runtimes like the browser (which...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
A bad practice should not be kept forever.
@arschmitz @runspired There needs to be a version that does not create a global. Even if I do not use any plugins, hammerjs still pollutes my namespace. Additionally more and more people continue to depend on the global because you continue to provide it.
It obviously is a chicken and egg problem but that is not a good reason to hold back the entire ecosystem.
moment did the right thing. moment deprecated their global. moment removed their global. moment broke many people’s apps. moment broke apps I was responsible for maintaining (forgot to import and paid the price). They did the right thing.
Please consider deprecating your global, giving plugin authors time to update and users time to decide, and then remove it completely.