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 - console warning #5033

Closed
ivodolenc opened this issue Jun 11, 2023 · 7 comments
Closed

Circular dependencies - console warning #5033

ivodolenc opened this issue Jun 11, 2023 · 7 comments

Comments

@ivodolenc
Copy link

Rollup Version

3.25.0

Operating System (or Browser)

mac

Node Version (if applicable)

18.12.1

Link To Reproduction

Expected Behaviour

No console warnings.

Actual Behaviour

Hi, in the latest version 3.25.0 it throws a warning in the console on build: (!) Circular dependencies ...

In the previous version 3.24.1 this is not the case.

@TrickyPi
Copy link
Member

Rollup@3.24.1 also throws a warning in the console, Could you provide a minimal repro?

Screenshot 2023-06-11 at 11 06 13 PM

@ivodolenc
Copy link
Author

Ok, I deleted node_modules and package-lock.json and reinstall dependencies. It turns out that there is a warning in 3.24.1 as well. Interesting, because in other projects with almost the same setup I don't get any warnings.

I forgot to mention, this only applies to types, for code I don't get warnings.

I export all the types that I manually create in the project so that the user can import these types later if he needs them. I guess that's why it gives that warning, although I read somewhere in the official typescript repo that it's perfectly fine to re-export everything in types.

Also, I found in the documentation onwarn option that can be used to manually silence this warning.

Here is a simple example:

// rollup.config.js

import { defineConfig } from 'rollup'
import esbuild from 'rollup-plugin-esbuild'
import dts from 'rollup-plugin-dts'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import pkg from './package.json' assert { type: 'json' }

const exports = {
  main: pkg.exports['.']
}

const noop = () => {}

export default defineConfig([
  {
    input: './src/index.ts',
    output: [
      { file: exports.main.import, format: 'esm' },
      { file: exports.main.require, format: 'cjs' }
    ],
    plugins: [nodeResolve(), esbuild()]
  },
  {
    input: './src/types/index.ts',
    output: { file: exports.main.types, format: 'esm' },
    plugins: [dts()],
    // Silences the warning only for `circular dependency`
    onwarn(warning) {
      if (warning.code === 'CIRCULAR_DEPENDENCY') noop
      else console.log(warning)
    }
  }
])

It would be great if there was an official option to deactivate individual warnings with simple boolean.

  {
    input: './src/types/index.ts',
    output: { file: exports.main.types, format: 'esm' },
    plugins: [dts()],
    // quick example
    warnings: {
      circularDependency: false
    }
  }

@TrickyPi
Copy link
Member

TrickyPi commented Jun 12, 2023

Hmmm, Maybe we can have a config to filter logs?
like this

{
   disabledLogs: [ 'CIRCULAR_DEPENDENCY', 'CIRCULAR_REEXPORT' ]
}

@lukastaegert looking forward to your thoughts.

@lukastaegert
Copy link
Member

Not yet convinced about this. It does not appear to be much shorter than writing a function, so the convenience would be limited. In any case, I am currently working on a related feature that should probably be finalised first: #5035

As I only have a phone for the next two weeks, it will take a little time to be completed, though.

@TrickyPi
Copy link
Member

TrickyPi commented Jun 14, 2023

It does not appear to be much shorter than writing a function

yeah, I think so too.

As I only have a phone for the next two weeks,

Oh, I'm sorry if I bothered you.

@ivodolenc
Copy link
Author

Hmm, it seems that this is not a bug after all, and there is a solution for manually silencing the warning.

So, as far as I'm concerned, you can close this as resolved.

@ivodolenc
Copy link
Author

According to this example from Lukas, I was able to silence the warning and it works as expected.

Here is a complete example if anyone is interested:

// rollup.config.js

import { defineConfig } from 'rollup'
import { getLogFilter } from 'rollup/getLogFilter'
import esbuild from 'rollup-plugin-esbuild'
import dts from 'rollup-plugin-dts'
import pkg from './package.json' assert { type: 'json' }

const exports = {
  main: pkg.exports['.']
}

// Filters logs
const logFilter = getLogFilter(['!code:CIRCULAR_DEPENDENCY'])
const onLog = (level, log, handler) => {
  if (logFilter(log)) handler(level, log)
}

export default defineConfig([
  {
    input: './src/index.ts',
    output: [
      { file: exports.main.import, format: 'esm' },
      { file: exports.main.require, format: 'cjs' }
    ],
    plugins: [esbuild()]
  },
  {
    input: './src/types/index.ts',
    output: { file: exports.main.types, format: 'esm' },
    plugins: [dts()],
    onLog
  }
  // ...
])

Thanks for your time and help 👍 I'm closing this as resolved.

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

No branches or pull requests

3 participants