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

Having "react" in optimizeDeps.include creates problems when "react" is externalized #277

Closed
7 tasks done
MilanKovacic opened this issue Jan 3, 2024 · 3 comments
Closed
7 tasks done

Comments

@MilanKovacic
Copy link

Describe the bug

Currently, plugin automatically sets react, and runtimes into optimizeDeps.include.

When react is externalized during development (and for example, provided through import maps) this behavior is unwanted and results in various warnings / errors.

Is there a possibility that this behavior could be made opt-in, or something similar?

Reproduction

Not relevant

Steps to reproduce

No response

System Info

Not relevant

Used Package Manager

npm

Logs

No response

Validations

@ArnaudBarre
Copy link
Member

What's the need to externalized deps in dev?

@MilanKovacic
Copy link
Author

MilanKovacic commented Jan 4, 2024

One of the common use cases is when utilizing microfrontends architecture, where all microfrontends consume the same version of "react", for example, provided through import maps — to avoid issues with multiple instances of react.

Discussions on this topic:

vitejs/vite#6582
vitejs/vite#2483

@ArnaudBarre
Copy link
Member

Yeah as you encounter this kind of need (micro-frontend, module federation, multiple dev server in dev, ...) is not supported by Vite today. I think @yyx990803 wants that to be better supported in the revamp with Rolldown, but until I'm not personally willing to add support for these feature requests that feels like Conway's low for me.
As already mentioned in multiple other issues, Vite is really flexible as soon as your keep one dev server, and you can have an index.html with <div id="app1"></div><div id="app1"></div> and an index.tsx with import "../../app1/src/index.tsx"; import "../../app2/src/index.tsx"; that will boot both apps.

Anyway, if really you want to go forward with this separation of dev-servers, you can inject a plugin that does something like:

{
  name: "remove-react-optimized",
  config(config) {
    config.optimizeDeps.include = config.optimizeDeps.include.filter(
      (d) => d !== 'react' && !d.startsWith("react/"),
    )
  }
}

(Not tested but should work when added after the react plugins)

@ArnaudBarre ArnaudBarre closed this as not planned Won't fix, can't repro, duplicate, stale Jan 4, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jan 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants