Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module: warn on using unfinished circular dependency #29935

Closed
wants to merge 3 commits into from

Commits on Oct 11, 2019

  1. module: warn on using unfinished circular dependency

    Warn when a non-existent property of an unfinished module.exports
    object is being accessed, as that very often indicates the presence
    of a hard-to-detect and hard-to-debug problem.
    
    This mechanism is only used if `module.exports` is still a
    regular object at the point at which the second, circular `require()`
    happens.
    
    The downside is that, temporarily, `module.exports` will have a
    prototype other than `Object.prototype`, and that there may
    be valid uses of accessing non-existent properties of unfinished
    `module.exports` objects.
    
    Performance of circular require calls in general is not
    noticeably impacted.
    
                                                   confidence improvement accuracy (*)   (**)  (***)
         module/module-loader-circular.js n=10000                 3.96 %       ±5.12% ±6.82% ±8.89%
    
    Example:
    
        $ cat a.js
        'use strict';
        const b = require('./b.js');
    
        exports.fn = () => {};
        $ cat b.js
        'use strict';
        const a = require('./a.js');
    
        a.fn();
        $ node a.js
        (node:1617) Warning: Accessing non-existent property 'fn' of module exports inside circular dependency
        /tmp/b.js:4
        a.fn();
          ^
    
        TypeError: a.fn is not a function
            at Object.<anonymous> (/tmp/b.js:4:3)
            [...]
    addaleax committed Oct 11, 2019
    Configuration menu
    Copy the full SHA
    eaa5cc5 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    dd1cdfa View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    3ba4313 View commit details
    Browse the repository at this point in the history