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

SSR support circular dependency #2258

Closed
3 tasks done
axe-me opened this issue Feb 26, 2021 · 3 comments · Fixed by #3950
Closed
3 tasks done

SSR support circular dependency #2258

axe-me opened this issue Feb 26, 2021 · 3 comments · Fixed by #3950
Labels
enhancement New feature or request feat: ssr p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority)

Comments

@axe-me
Copy link
Contributor

axe-me commented Feb 26, 2021

  • Read the docs.
  • Use Vite >=2.0. (1.x is no longer supported)
  • If the issue is related to 1.x -> 2.0 upgrade, read the Migration Guide first.

Describe the bug

When loading an SSR module with circular dependency (Many to many relationships TypeORM entities for example), the cli is stuck.
And sometime I get the Circular dependency: warning, sometimes I don't.

To be honest, I'm not sure this is a bug, lots of backend code written in this pattern. In my opinion, circular dependency should be allowed for SSR. But I'm not sure how can you patch the modGraph with circular dependency in it.

Reproduction

https://github.com/axe-me/repro-vite-circular-dependency

System Info

  • vite version: 2.0.3
  • Operating System: macos
  • Node version: 14
  • Package manager (npm/yarn/pnpm) and version: npm 7

Logs (Optional if provided reproduction)

image

@yyx990803 yyx990803 changed the title [Bug?] cant load ssr module when modules import each other SSR support circular dependency Feb 26, 2021
@yyx990803 yyx990803 added enhancement New feature or request and removed pending triage labels Feb 26, 2021
@airhorns
Copy link
Contributor

airhorns commented Mar 4, 2021

FWIW I have seen circular module references work fine with vite SSR so there might be something deeper going on here. Also, it seems a bit weird that you'd be requiring code for SSR that does TypeORM stuff -- are you using TypeORM on the client? If not, you may be able to get around your issue by requiring only the code that needs to go out to the client through vite SSR.

@axe-me
Copy link
Contributor Author

axe-me commented Mar 4, 2021

@airhorns I wrote a plugin https://github.com/axe-me/vite-plugin-node for using vite as node dev server. Even for SSR, some vue projects using VuexORM etc will also have similar issue.

@pmatisko
Copy link

pmatisko commented May 26, 2021

Dev SSR circular dependencies don't work in a very simple example. SPA works, final SSR build works too.

//a.js
export function a() { ... }
//b.js
import { a } from '@IoC'

export function b() {  
   a()   
} 
//IoC.js
export { a } from 'a'
export { b } from 'b'

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request feat: ssr p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority)
Projects
None yet
6 participants