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.

Exported hoisted functions not moved to the top of Common JS module

See original GitHub issue

Currently, there’s an issue when consuming Common JS modules from node_modules where hoisted function declarations are converted to var assignments and not moved to the top of the file. There’s a particular example in React ( see https://github.com/facebook/react/issues/8894 for more context, and a specific code example) which demonstrates this issue.

I also found this in other modules, such as json-stringify-safe (https://github.com/isaacs/json-stringify-safe/blob/5930d6e51c58cf3a134f36301b029408bcfd09e5/stringify.js#L1-L6).

This seems to be a bug in Closure Compiler, and seems to only happen when that particular function is exported from the module.

Please excuse me if this has already been mentioned somewhere. From a quick search through the issues I couldn’t find anything related.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
ChadKillingsworthcommented, Feb 6, 2017

No problem at all - I rarely get such exact bug reports. I’m actually working on a fix right now.

0reactions
ChadKillingsworthcommented, Feb 27, 2017

Closed by 5e0a570

Read more comments on GitHub >

github_iconTop Results From Across the Web

node "require" hoisted to top outside of script -- loses access ...
All my require statements are hoisted to the top. This creates a problem because when the methods within those imported scripts are invoked...
Read more >
CommonJS vs. ES Modules: Modules and Imports in NodeJS
With ES Modules, imports are static, which means they are executed at parse time. This is why imports are “hoisted”. They are implicitly...
Read more >
16. Modules - Exploring JS
In CommonJS, imports are copies of exported values; 16.7.2. ... Module imports are hoisted (internally moved to the beginning of the current scope)....
Read more >
CommonJS vs ES Modules in Node.js - A Detailed Comparison
CommonJS modules do not have exports or prototypes like ES modules do. ... imports are "hoisted", as they are implicitly moved to the...
Read more >
Scope Hoisting - Parcel
This negates the advantages of scope-hoisting because moving the exports into ... a function an if statement) using CommonJS require , this isn't...
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