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

Dealing With Circular Dependencies #12

Closed
LydiaF opened this issue Mar 19, 2021 · 5 comments
Closed

Dealing With Circular Dependencies #12

LydiaF opened this issue Mar 19, 2021 · 5 comments

Comments

@LydiaF
Copy link

LydiaF commented Mar 19, 2021

Dear @brillout,

We are encountering circular dependencies when using recursive functions. I was wondering if this is something to do with vite & ssr, or whether it was perhaps your package. I thought it might be just vite & ssr because there is an issue about it, but I thought it might be your package as all the circular dependencies begin with this: /Users/home1/code/lt/csvite/node_modules/vite-plugin-ssr/user-files/infra.node.vite-entry.ts -> /src/pages/tests/index.page.tsx -> ...

I tried putting this in vite.config.ts, but it didn't do anything.

build: {
    rollupOptions: {
      onwarn(warning, rollupWarn) {
        if (warning.code !== 'CIRCULAR_DEPENDENCY') {
          rollupWarn(warning)
        }
      },
    },
  },

Thank you (again!) for any pointers and apologies if this is nothing to do with vite-plugin-ssr!

@brillout
Copy link
Member

It probably has nothing to do with vite-plugin-ssr (hence closing this ticket). Give me a full error stack and I'll have a closer look.

@LydiaF
Copy link
Author

LydiaF commented Mar 20, 2021

Dear Romuald,

Thanks for replying so quickly. I made two repositories showing this example.

  1. Official Vite Starter
    This doesn't print "Circular Dependency"

  2. vite-plugin-ssr
    This does print "Circular Dependency"...

Circular dependency: /Users/home1/code/vite-plugin-ssr-circ-deps/node_modules/vite-plugin-ssr/user-files/infra.node.vite-entry.ts -> /pages/index.page.tsx -> /comps/index.ts -> /comps/handleObject.js -> /comps/index.ts

(There is also a TypeError logging but nevermind that :))

Thank you so much for looking into this if you have time. We have a lot of such functions and the circular dependencies are crashing everything.

Warmest wishes,

Lydia

@brillout
Copy link
Member

AFAICT there are only two optoins here. Either you:

It's time consuming but definitely possible to get rid of all cyclic dependency.

E.g. the cyclic dependency

/comps/index.ts -> /comps/handleObject.js -> /comps/index.ts

is fairly easy to resolve.

@LydiaF
Copy link
Author

LydiaF commented Mar 20, 2021

Dear Romuald,

Thank you so much for your help and even more so the encouragement/nudge!!

I was able to resolve this /comps/index.ts -> /comps/handleObject.js -> /comps/index.ts using the solution in stack overflow...

But, in our code these functions had more than just 'one door', you can call handleObject() in and of itself. Anyway I have surprised myself and managed to work out how to do it!!!!

Nevertheless I might hold out for as long as I can for 2258 as this is going to be horrible refactor....

THANK YOU!!

@brillout
Copy link
Member

brillout commented Mar 20, 2021 via email

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