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.

Library is broken in environment using CommonJS modules

See original GitHub issue

Library is broken in CommonJS environment. Module is wrapped into anonymous function to provide something close to UMD module format:

(function(ns) {'use strict';
    // code
}(typeof module !== "undefined" ? module.exports : window));

It works perfectly in non-CommonJS environment, since it sets ns to Window. In CommonJS environment ns will be module exports object. But code of the library extensively uses ns variable to access Window’s properties: 1, 2, 3, etc. Obviously in CommonJS environment these properties are undefined, so it fails/behaves very weird (in my case animation went insane, because ns.performance was undefined and it used Date.now() to get animation start time (and they are completely different things).

The simple solution would be just removing ns. prefix from all the global variables. If you think we should go with this solution, I can prepare PR.

Check out updated example to get simple reproduction of the issue in CommonJS environment.


As a side note. I find the Regex based build process a bit speculative. Any reason why you use that instead something like this babel plugin for example? Maybe we can improve build process as well?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Mikhuscommented, Oct 18, 2016
0reactions
socmagcommented, Oct 15, 2016

sry… how about being able to specify your own time provider when creating the gauge? would that help?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node Modules at War: Why CommonJS and ES ... - Code Red
Since the dawn of Node, Node modules were written as CommonJS modules. We use require() to import them. When implementing a module for...
Read more >
microsoft/sp-core-library commonjs build broken #7027 - GitHub
The package @microsoft/sp-core-library now uses a broken commonjs build by default rather than the previously shipped esmodule build.
Read more >
Avoid these issues when using new ECMAScript modules in ...
Most typescript applications importing commonjs modules should turn on esModuleInterop in their tsconfig file. Then you can just use a “normal” ...
Read more >
CommonJS modules | Node.js v19.3.0 Documentation
CommonJS modules are the original way to package JavaScript code for Node.js. Node.js also supports the ECMAScript modules standard used by browsers and ......
Read more >
How the module system, CommonJS & require works
Learn how the Node.js module system & CommonJS works and what does ... Dependency Injection is rarely used in a Node.js environment, ...
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