Open Stnaire opened 6 years ago
If you look inside "node_modules/inversify/lib/syntax/binding_on_syntax.js" you got on the third line:
var binding_when_syntax_1 = require("./binding_when_syntax");
and in "node_modules/inversify/lib/syntax/binding_when_syntax.js" there is on the third line too:
var binding_on_syntax_1 = require("./binding_on_syntax");
How can it work? I'm really surprised to be the only one having this problem.
For now I'm commenting the whole binding_on_syntax
thing so I can compile:
// "use strict";
// Object.defineProperty(exports, "__esModule", { value: true });
// var binding_when_syntax_1 = require("./binding_when_syntax");
// var BindingOnSyntax = (function () {
// function BindingOnSyntax(binding) {
// this._binding = binding;
// }
// BindingOnSyntax.prototype.onActivation = function (handler) {
// this._binding.onActivation = handler;
// return new binding_when_syntax_1.BindingWhenSyntax(this._binding);
// };
// return BindingOnSyntax;
// }());
// exports.BindingOnSyntax = BindingOnSyntax;
exports.BindingOnSyntax = function() { };
It doesn't seem to break what I use so it will do for now, but help would be greatly appreciated.
Thanks.
@Stnaire can you please share your webpack config? Or a repo set up to recreate the issue?
Thanks
Hi and thanks for your response.
My webpack config is a generic script driven by a YAML configuration file (kind of what I did with a gulp plugin I've made several years ago, gulp-yaml-packages).
But I created a sandbox project and I proceed to remove most of the code to create the simplest demo possible while still using the same code base.
That forced me to read the whole script again and...
private getCommonPlugins(): any[] {
const output: any[] = [
[...]
new CircularDependencyPlugin({
exclude: /node_modules/,
onDetected({ paths, compilation }) {
compilation.errors.push(new Error(paths.join(" -> ")));
},
}),
];
[...]
}
I totally forgot about this CircularDependencyPlugin
I've added here maybe 1 year ago. And because the error doesn't identify the plugin I didn't think about it...
But that's not enough, I've excluded node_modules
in the configuration, so a circular dependency in inversify shouldn't trigger the error.
If I go in the plugin's source code, that's what I find:
for (let module of modules) {
if (module.resource === undefined) { continue }
let maybeCyclicalPathsList = this.isCyclic(module, module, {})
if (maybeCyclicalPathsList) {
// allow consumers to override all behavior with onDetected
if (plugin.options.onDetected) {
try {
plugin.options.onDetected({
module: module,
paths: maybeCyclicalPathsList,
compilation: compilation
})
} catch(err) {
compilation.errors.push(err)
}
continue
}
// exclude modules based on regex test
if (plugin.options.exclude.test(module.resource)) {
continue
}
[...]
}
[...]
}
So the isCyclic
test is done before checking the exclusion rule, and if the configuration defines a onDetected
callback then the error is sent to it.
I had no idea that the exclude
test what supposed to be done manually in the onDetected
callback, and that's weird.
I've updated the plugin to its latest version and now the code is:
for (let module of modules) {
const shouldSkip = (
module.resource == null ||
plugin.options.exclude.test(module.resource)
)
// skip the module if it matches the exclude pattern
if (shouldSkip) {
continue
}
let maybeCyclicalPathsList = this.isCyclic(module, module, {})
if (maybeCyclicalPathsList) {
// allow consumers to override all behavior with onDetected
if (plugin.options.onDetected) {
try {
plugin.options.onDetected({
module: module,
paths: maybeCyclicalPathsList,
compilation: compilation
})
} catch(err) {
compilation.errors.push(err)
}
continue
}
[...]
}
Now they perform the exclusion test first and it solves the problem.
But still, it seems to me that there is a design problem anyway. Two files shouldn't depend on one another in such a way, a third component should be created to expose the functionality they both depend on.
Thanks for your response, that forced me to investigate deeper.
I'm getting similar warnings when trying to compile using rollup with babel 7:
(!) Circular dependency: node_modules\inversify\lib\syntax\binding_on_syntax.js -> node_modules\inversify\lib\syntax\binding_when_syntax.js -> node_modules\inversify\lib\syntax\binding_on_syntax.js
(!) Circular dependency: node_modules\inversify\lib\syntax\binding_on_syntax.js -> node_modules\inversify\lib\syntax\binding_when_syntax.js -> C:\Users\modified\library\node_modules\inversify\lib\syntax\binding_on_syntax.js?commonjs-proxy -> node_modules\inversify\lib\syntax\binding_on_syntax.js
I am getting the same warnings using rollup with typescript:
(!) Circular dependency: node_modules/inversify/lib/syntax/binding_on_syntax.js -> node_modules/inversify/lib/syntax/binding_when_syntax.js -> node_modules/inversify/lib/syntax/binding_on_syntax.js
(!) Circular dependency: node_modules/inversify/lib/syntax/binding_on_syntax.js -> node_modules/inversify/lib/syntax/binding_when_syntax.js -> /Users/pestix/git/6502ts/6502.ts/node_modules/inversify/lib/syntax/binding_on_syntax.js?commonjs-proxy -> node_modules/inversify/lib/syntax/binding_on_syntax.js
I have the same issue:
WARNING: Circular dependency: node_modules/inversify/lib/syntax/binding_on_syntax.js -> node_modules/inversify/lib/syntax/binding_when_syntax.js -> node_modules/inversify/lib/syntax/binding_on_syntax.js
@Adamfsk @DirtyHairy @davidstellini this should solve the circular dependency issue;
// rollup.config.js
plugins: [
commonjs({
dynamicRequireTargets: [
'node_modules/inversify/lib/syntax/binding_{on,when}_syntax.js',
],
}),
],
Documentation: https://github.com/rollup/plugins/blob/master/packages/commonjs/README.md#dynamicrequiretargets
I got a strange error indicating there is a circular dependency in the library.
Current Behavior
Compilation fails with the following errors:
Steps to Reproduce (for bugs)
Simply create a ts file doing an import of the container and a console.log so the compiler do not ignore the import:
This, for me, is enough to create the bug.
Stack trace