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

Circular dependencies warning when using ajv@7.0.3 #1399

Closed
josdejong opened this issue Jan 20, 2021 · 11 comments
Closed

Circular dependencies warning when using ajv@7.0.3 #1399

josdejong opened this issue Jan 20, 2021 · 11 comments
Milestone

Comments

@josdejong
Copy link
Contributor

I'm upgrading a library to ajv@7.0.3, and rollup gives me the following warning:

(!) Circular dependencies
node_modules\ajv\dist\compile\validate\dataType.js -> node_modules\ajv\dist\compile\util.js -> node_modules\ajv\dist\compile\validate\index.js -> node_modules\ajv\dist\compile\validate\dataType.js
node_modules\ajv\dist\compile\validate\dataType.js -> node_modules\ajv\dist\compile\util.js -> node_modules\ajv\dist\compile\validate\index.js -> node_modules\ajv\dist\compile\validate\iterate.js -> node_modules\ajv\dist\compile\validate\dataType.js
node_modules\ajv\dist\compile\validate\index.js -> node_modules\ajv\dist\compile\validate\iterate.js -> node_modules\ajv\dist\compile\validate\defaults.js -> node_modules\ajv\dist\compile\validate\index.js
...and 10 more

It is no showstopper, but it would be great if the code would not contain these circular references.

@sdescarries
Copy link

Observed the same issue in a react-native app. I believe it's the checkStrictMode function that is defined in compile/validate/index.ts and used in compile/util.ts causing the circular dependency.

I tried patching this but the function cannot easily be extracted into a separate file, it depends on the SchemaCxt type which is defined directly in the index. Definitely doable but involves a lot of refactoring.

@epoberezkin
Copy link
Member

typescript doesn't seem to mind it, probably there is some setting to warn on it...

Could you post the full list of circles? Or you have to remove them one by one so it should the next (rather than "and 10 more")?

@josdejong
Copy link
Contributor Author

I had a short look but do not see a way to have rollup output all circular dependencies instead of the first three and "...and 10 more".

One way to reproduce this issue yourself:

git clone git@github.com:josdejong/svelte-jsoneditor.git
cd svelte-jsoneditor
npm install
npm start

I didn't find the time yet to create an isolated demo in an empty project, sorry.

Maybe a tool like https://github.com/dependents/node-dependency-tree can be helpful to find the circular dependencies.

@Bgshanoams
Copy link

Bgshanoams commented Feb 14, 2021 via email

@caoxiemeihao
Copy link

typescript doesn't seem to mind it, probably there is some setting to warn on it...

Could you post the full list of circles? Or you have to remove them one by one so it should the next (rather than "and 10 more")?

The below three files from node_modules:

  • node_modules\conf\node_modules\ajv\dist\compile\validate\dataType.js
const rules_1 = require("../rules");
const applicability_1 = require("./applicability");
const errors_1 = require("../errors");
const codegen_1 = require("../codegen");
const util_1 = require("../util"); 
  • node_modules\conf\node_modules\ajv\dist\compile\util.js
const codegen_1 = require("./codegen");
const validate_1 = require("./validate");
  • node_modules\conf\node_modules\ajv\dist\compile\validate\index.js
const boolSchema_1 = require("./boolSchema");
const dataType_1 = require("./dataType");
const iterate_1 = require("./iterate");
const codegen_1 = require("../codegen");
const names_1 = require("../names");
const resolve_1 =  @require("../resolve");
const util_1 = require("../util");

@caoxiemeihao
Copy link

caoxiemeihao commented Mar 11, 2021

这个警告在 webpack 下并不会报出来
我是使用了 rollup 才得到了这个警告
可见 webpack 处理这种情况要更加智能一些
最后我通过 rollup.config.ts 配置屏蔽这种警告输出


This warning will not be reported under webpack
I got this warning by using rollup
It can be seen that webpack is more intelligent in dealing with this situation
Finally, I passed rollup.config.ts Configure to mask this warning output


onwarn: warning => {
    if (warning.code !== 'CIRCULAR_DEPENDENCY') {
        console.error(`(!) ${warning.message}`);
    }
}

@josdejong
Copy link
Contributor Author

josdejong commented Mar 13, 2021

Thanks for sharing this solution to suppress the circular dependency warnings, it works.

It can be seen that webpack is more intelligent in dealing with this situation

I guess that depends: circular dependencies are often a bad thing, so having rollup warn about this may be a good thing 😄

@epoberezkin epoberezkin added this to the 8.0.0 milestone Mar 14, 2021
@epoberezkin
Copy link
Member

epoberezkin commented Mar 14, 2021

Looking into it now. Some circular dependencies are "import type", they are not present in .js files. I was wondering if it's changed since 7.0.3 or is rollup unhappy about circular type dependencies as well? (although errors do point to to .js files).

Also, is there some good way to detect them in typescript? I've only found some JS eslint plugin...

@josdejong
Copy link
Contributor Author

Looking into it now. Some circular dependencies are "import type", they are not present in .js files

The circular dependencies are really in the JavaScript code. I'm not sure if the TS files contain more circular dependencies.

I was wondering if it's changed since 7.0.3

Just for clarity: I encountered this since upgrading from v6 to v7, not v7.0.3 specific.

Also, is there some good way to detect them in typescript?

I'm not sure, except that rollup seems to be good at this 😉

Using the custom onwarn property in rollup it is easy to output all warnings. Here you go:

Click to expand all circular dependencies
{
  cycle: [
    'node_modules\ajv\dist\compile\validate\dataType.js',
    'node_modules\ajv\dist\compile\util.js',
    'node_modules\ajv\dist\compile\validate\index.js',
    'node_modules\ajv\dist\compile\validate\dataType.js'
  ],
  importer: 'node_modules\ajv\dist\compile\validate\dataType.js'
}
{
  code: 'CIRCULAR_DEPENDENCY',
  cycle: [
    'node_modules\ajv\dist\compile\validate\dataType.js',
    'node_modules\ajv\dist\compile\util.js',
    'node_modules\ajv\dist\compile\validate\index.js',
    'node_modules\ajv\dist\compile\validate\iterate.js',
    'node_modules\ajv\dist\compile\validate\dataType.js'
  ],
  importer: 'node_modules\ajv\dist\compile\validate\dataType.js'
}
{
  code: 'CIRCULAR_DEPENDENCY',
  cycle: [
    'node_modules\ajv\dist\compile\validate\index.js',
    'node_modules\ajv\dist\compile\validate\iterate.js',
    'node_modules\ajv\dist\compile\validate\defaults.js',
    'node_modules\ajv\dist\compile\validate\index.js'
  ],
  importer: 'node_modules\ajv\dist\compile\validate\index.js'
}
{
  code: 'CIRCULAR_DEPENDENCY',
  cycle: [
    'node_modules\ajv\dist\compile\validate\index.js',
    'node_modules\ajv\dist\compile\validate\iterate.js',
    'node_modules\ajv\dist\compile\validate\defaults.js',
    'node_modules\ajv\dist\compile\validate\index.js?commonjs-proxy',
    'node_modules\ajv\dist\compile\validate\index.js'
  ],
  importer: 'node_modules\ajv\dist\compile\validate\index.js'
}
{
  code: 'CIRCULAR_DEPENDENCY',
  cycle: [
    'node_modules\ajv\dist\compile\context.js',
    'node_modules\ajv\dist\compile\validate\dataType.js',
    'node_modules\ajv\dist\compile\util.js',
    'node_modules\ajv\dist\compile\validate\index.js',
    'node_modules\ajv\dist\compile\validate\iterate.js',
    'node_modules\ajv\dist\compile\validate\keyword.js',
    'node_modules\ajv\dist\compile\context.js'
  ],
  importer: 'node_modules\ajv\dist\compile\context.js'
}
{
  code: 'CIRCULAR_DEPENDENCY',
  cycle: [
    'node_modules\ajv\dist\compile\util.js',
    'node_modules\ajv\dist\compile\validate\index.js',
    'node_modules\ajv\dist\compile\validate\iterate.js',
    'node_modules\ajv\dist\compile\validate\keyword.js',
    'node_modules\ajv\dist\vocabularies\code.js',
    'node_modules\ajv\dist\compile\util.js'
  ],
  importer: 'node_modules\ajv\dist\compile\util.js'
}
{
  code: 'CIRCULAR_DEPENDENCY',
  cycle: [
    'node_modules\ajv\dist\compile\validate\index.js',
    'node_modules\ajv\dist\compile\validate\iterate.js',
    'node_modules\ajv\dist\compile\validate\keyword.js',
    'node_modules\ajv\dist\vocabularies\code.js',
    'node_modules\ajv\dist\compile\subschema.js',
    'node_modules\ajv\dist\compile\validate\index.js'
  ],
  importer: 'node_modules\ajv\dist\compile\validate\index.js'
}
{
  code: 'CIRCULAR_DEPENDENCY',
  cycle: [
    'node_modules\ajv\dist\compile\util.js',
    'node_modules\ajv\dist\compile\validate\index.js',
    'node_modules\ajv\dist\compile\validate\iterate.js',
    'node_modules\ajv\dist\compile\validate\keyword.js',
    'node_modules\ajv\dist\vocabularies\code.js',
    'node_modules\ajv\dist\compile\subschema.js',
    'node_modules\ajv\dist\compile\util.js'
  ],
  importer: 'node_modules\ajv\dist\compile\util.js'
}
{
  code: 'CIRCULAR_DEPENDENCY',
  cycle: [
    'node_modules\ajv\dist\compile\util.js',
    'node_modules\ajv\dist\compile\validate\index.js',
    'node_modules\ajv\dist\compile\validate\iterate.js',
    'node_modules\ajv\dist\compile\validate\keyword.js',
    'node_modules\ajv\dist\vocabularies\code.js',
    'node_modules\ajv\dist\compile\subschema.js',
    'node_modules\ajv\dist\compile\util.js?commonjs-proxy',
    'node_modules\ajv\dist\compile\util.js'
  ],
  importer: 'node_modules\ajv\dist\compile\util.js'
}
{
  code: 'CIRCULAR_DEPENDENCY',
  cycle: [
    'node_modules\ajv\dist\compile\context.js',
    'node_modules\ajv\dist\compile\validate\dataType.js',
    'node_modules\ajv\dist\compile\util.js',
    'node_modules\ajv\dist\compile\validate\index.js',
    'node_modules\ajv\dist\compile\validate\iterate.js',
    'node_modules\ajv\dist\compile\validate\keyword.js',
    'node_modules\ajv\dist\compile\context.js?commonjs-proxy',
    'node_modules\ajv\dist\compile\context.js'
  ],
  importer: 'node_modules\ajv\dist\compile\context.js'
}
{
  code: 'CIRCULAR_DEPENDENCY',
  cycle: [
    'node_modules\ajv\dist\compile\util.js',
    'node_modules\ajv\dist\compile\validate\index.js',
    'node_modules\ajv\dist\compile\validate\iterate.js',
    'node_modules\ajv\dist\compile\util.js'
  ],
  importer: 'node_modules\ajv\dist\compile\util.js'
}
{
  code: 'CIRCULAR_DEPENDENCY',
  cycle: [
    'node_modules\ajv\dist\compile\validate\index.js',
    'node_modules\ajv\dist\compile\validate\iterate.js',
    'node_modules\ajv\dist\compile\validate\index.js'
  ],
  importer: 'node_modules\ajv\dist\compile\validate\index.js'
}
{
  code: 'CIRCULAR_DEPENDENCY',
  cycle: [
    'node_modules\ajv\dist\compile\validate\dataType.js',
    'node_modules\ajv\dist\compile\util.js',
    'node_modules\ajv\dist\compile\validate\index.js',
    'node_modules\ajv\dist\compile\validate\iterate.js',
    'node_modules\ajv\dist\compile\validate\dataType.js?commonjs-proxy',
    'node_modules\ajv\dist\compile\validate\dataType.js'
  ],
  importer: 'node_modules\ajv\dist\compile\validate\dataType.js'
}
{
  code: 'CIRCULAR_DEPENDENCY',
  cycle: [
    'node_modules\ajv\dist\compile\util.js',
    'node_modules\ajv\dist\compile\validate\index.js',
    'node_modules\ajv\dist\compile\resolve.js',
    'node_modules\ajv\dist\compile\util.js'
  ],
  importer: 'node_modules\ajv\dist\compile\util.js'
}
{
  code: 'CIRCULAR_DEPENDENCY',
  cycle: [
    'node_modules\ajv\dist\compile\util.js',
    'node_modules\ajv\dist\compile\validate\index.js',
    'node_modules\ajv\dist\compile\util.js'
  ],
  importer: 'node_modules\ajv\dist\compile\util.js'
}

@epoberezkin
Copy link
Member

epoberezkin commented Mar 14, 2021

rollup seems to be good at this

I was hoping to do it with typescript somehow, to avoid adding something like rollup, also rollup doesn't fail when it has cycles - I can probably make it throw exceptions with config but not with CLI.

Anyway, it's resolved in v8 branch, I just used rollup ./dist/ajv.js --file bundle.js --format iife --plugin=@rollup/plugin-commonjs --plugin=@rollup/plugin-json

@epoberezkin epoberezkin mentioned this issue Mar 14, 2021
Merged
11 tasks
@josdejong
Copy link
Contributor Author

I can confirm that the circular dependencies are resolved in v8, thanks Evgeny!

andriyl pushed a commit to Redocly/ajv that referenced this issue Jun 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

5 participants