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

Error sharing "react-dom" in dev mode #88

Closed
RussellCanfield opened this issue Sep 16, 2024 · 17 comments · Fixed by #90
Closed

Error sharing "react-dom" in dev mode #88

RussellCanfield opened this issue Sep 16, 2024 · 17 comments · Fixed by #90

Comments

@RussellCanfield
Copy link
Contributor

RussellCanfield commented Sep 16, 2024

Everything has been working pretty well so far 🙂 I did run into one issue when sharing "react-dom" in dev mode:

chunk-5GRLQEB4.js?v=8f475596:27 Uncaught (in promise) TypeError: factory is not a function
    at chunk-5GRLQEB4.js?v=8f475596:27:29
    at async chunk-5GRLQEB4.js?v=8f475596:34:97

This line in the bundle:

const mfproxyawaitrequire_vite_mf_2_host_loadShare_react_mf_2_dom_loadShare = await require_vite_mf_2_host_loadShare_react_mf_2_dom_loadShare();

It seems like when it calls into the runtime, the host's options -> shared, is missing react-dom, although the Vite plugin specifies it.

Maybe in here?

@zhangHongEn
Copy link
Contributor

Can you provide a reproducible example?
Also, does it reproduce when you run this example?

@zhangHongEn
Copy link
Contributor

zhangHongEn commented Sep 17, 2024 via email

zhangHongEn pushed a commit to zhangHongEn/vite that referenced this issue Sep 18, 2024
gioboa pushed a commit that referenced this issue Sep 18, 2024
* fix: test #89

* fix: #88 #89

* doc: manifest

---------

Co-authored-by: 张洪恩 <zhanghongen@bwcj.com>
@tduforet
Copy link

Hello, I have the same error with my project using vite for the host and webpack for remotes but only on preview mode after a build. It works correctly in dev mode.

@gioboa
Copy link
Collaborator

gioboa commented Oct 25, 2024

Can you create a basic reproduction repo please?

@tduforet
Copy link

I tried but I don't have any errors with a simple project.

The error occurs here only with build and preview mode. It works correctly in dev mode.
Capture d’écran 2024-10-29 à 16 13 12

with these shared dependencies
Capture d’écran 2024-10-29 à 16 13 34

But I understand if you can't do anything without a reproduction repo.

@gioboa
Copy link
Collaborator

gioboa commented Oct 29, 2024

@tduforet are you using the latest release ?

@tduforet
Copy link

Yes, it wasn't the latest when I had the problem the first time. I updated the version to the latest and I always have the problem.

@gioboa
Copy link
Collaborator

gioboa commented Oct 29, 2024

I added the config below in the react example and it's working fine.

'react-dom': {
	singleton: true,
	strictVersion: true,
	requiredVersion: '18.3.1',
},
'react-router-dom': {
	singleton: true,
},

You can try to figure out step by step the piece of code that is creating that error. Without a failing example it's impossible to face the issue. I'm sorry

@tduforet
Copy link

Yes I understand, I try to add some log, the factory is false si maybe there is a problem on loadShare method for react.

Thanks for your help.

@zhangHongEn
Copy link
Contributor

Here’s an important issue. It only occurs in build mode, and it would be great if you could provide a reproducible example.

@tduforet
Copy link

tduforet commented Oct 30, 2024

Hello, I removed one by one the different plugins I had in my project and it seems the plugin vite-plugin-svgr (4.2.0) is the problem.
When I add it in a simple project with only the react plugin and federation plugin I also have the error.

@tduforet
Copy link

For now I don't understand why but it works only if I use the svgr plugin after the federation plugin in the vite config.

@zhangHongEn
Copy link
Contributor

zhangHongEn commented Oct 30, 2024

For now I don't understand why but it works only if I use the svgr plugin after the federation plugin in the vite config.

plugins: [
  federation(),
  svgr()
]

Will adjusting the order solve the problem? That would be great!

@tduforet
Copy link

Yes it works when svgr is after federation but I don't know why 😅

@zhangHongEn
Copy link
Contributor

The two plugins with "enforce": "pre" are conflicting; optimization could be considered.

@gioboa
Copy link
Collaborator

gioboa commented Oct 31, 2024

Yep, we need to consider it because we can have this kind of errors with many other plugins.

@zmzlois
Copy link
Contributor

zmzlois commented Oct 31, 2024

was thinking wrap federation under your own plugin and add a load()=>{} that does nothing to trick the AST re-parse

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

Successfully merging a pull request may close this issue.

5 participants