question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Don't create a window.Hammer global when in CommonJS

See original GitHub issue

In 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:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ibccommented, Dec 31, 2016

we have 3rd party plugins the depend on there being a global

A bad practice should not be kept forever.

1reaction
aluanhaddadcommented, Dec 30, 2016

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found