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

Suppress warning if any dependency in the circular chain is loaded completely #8

Closed
renehamburger opened this issue Sep 7, 2016 · 3 comments

Comments

@renehamburger
Copy link

Thanks for the plugin!

I'm in a situation where circular dependencies cannot be avoided altogether, but where some of the require calls can be postponed until the dependent modules are loaded completely. Here's an example:

const b = require('b');
export class a;
let a;
export class b {
  constructor() {
    a = require('a');
  }
};

As far as I can see, your plugin would flag this as a circular dependency, but it shouldn't be a problematic one, as module b could be required before it required a. Do you see any way to prevent warnings/errors for these cases?

@aackerman
Copy link
Owner

Yea, I would imagine you would use the exclude regex option. There is an example in the README. Please let me know if that isn't enough information to solve this issue.

@renehamburger
Copy link
Author

Yes, I could suppress the warning/error manually for circular dependencies that are not problematic. But my point is that the warning/error shouldn't be there in the first place if the circular dependency chain can be resolved by webpack, i.e., if one of the modules can be loaded because it requires it's successor after it has been loaded completely. Do you see what I mean?

@aackerman
Copy link
Owner

If I understand you correctly, you expect your code to not error. But you would expect something like the following to error.

const b = require('b');
export class a;
let a;
class b {
  constructor() {
    a = require('a');
    new a();
  }
}
new b();
export b; 

That type of static analysis is not something that can not be provided by this tool. Webpack itself analyzes import and require calls to build a dependency graph and construct a module bundle, it doesn't do any analysis of runtime semantics and this tool doesn't either.

The best this tool can do is identifying circular dependencies, which might identify a problem but requires a human to do further analysis.

I personally don't believe that a tool for JavaScript exists that could error in the way you would expect. Sorry to say I cannot provide this functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants