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

import: false not supported in the new runtime apis #2020

Open
2 tasks done
MadaraUchiha-314 opened this issue Jan 25, 2024 · 9 comments
Open
2 tasks done

import: false not supported in the new runtime apis #2020

MadaraUchiha-314 opened this issue Jan 25, 2024 · 9 comments
Assignees
Labels
🐞 bug Something isn't working

Comments

@MadaraUchiha-314
Copy link
Contributor

Clear and concise description of the problem

In webpack's module federation, there's a way to declare a shared dependency as import: false, when we do that the bundler doesn't build a fallback for that dependency and uses what ever is registered by other containers in the shared scope.

To implement this same functionality using the runtime apis, we need to provide the version information of the shared dependency to the init function, but there's no provision to do so because ShareArgs always require either lib or get to be provided.

The version information is important as there might be multiple versions of the same dependency registered in the shared scope and the requesting entity needs to be provided with the maxSatisfying version.

Suggested solution

Add an option to either explicitly specify that the fallback for the shared module is not provided by the container or make lib and get both optional forcing the runtime to look elsewhere for a fallback.

Alternative

No response

Additional context

No response

Validations

  • Read the Contributing Guidelines.
  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
@ScriptedAlchemy
Copy link
Member

Do you have a sample repo that demonstrates the issue?

@ScriptedAlchemy
Copy link
Member

Okay, I see what's wrong here. The way we parse versions has moved into the runtime. However, it appears that some of the fallback code was replaced with just the "require.ensure" fallback and not the other two checks. Instead, it was replaced with a "share throw error" on the getter, like you said. @2heal1 , do you have any ideas on how to re-enable this? I am working on a branch to try and add "ensureExistence", "fallback", and "load" methods to the Federation Runtime/Bundler Runtime.

@2heal1
Copy link
Member

2heal1 commented Feb 7, 2024

Do you mean set import:false in runtime.init ?

In build plugin ,it can work , you can check it in this demo.

But runtime.init may have errors , i will check it and fix .

@2heal1 2heal1 self-assigned this Feb 7, 2024
@2heal1
Copy link
Member

2heal1 commented Feb 7, 2024

Okay i check again , runtime indeed not has the options which relate toimport:false .

I will add the option in future.

Temp workaround is you can just set shared.get a function like ()=>'never called' , which you can confirm it will not be called , and just use others provide shared.

@MadaraUchiha-314
Copy link
Contributor Author

MadaraUchiha-314 commented Feb 7, 2024

@2heal1 I tried the approach you suggested, but that doesn't seem to work. The get or lib function seems to be called. I even tried the strategy: 'loaded-first', but that also doesn't seem to do it.

Example: MadaraUchiha-314/rollup-plugin-module-federation#35

import-false-not-working

Copy link
Contributor

github-actions bot commented Apr 8, 2024

Stale issue message

@MadaraUchiha-314
Copy link
Contributor Author

not stale.

@MadaraUchiha-314
Copy link
Contributor Author

@ScriptedAlchemy @2heal1 Is this complete by any chance ?

@MadaraUchiha-314
Copy link
Contributor Author

#2330 ??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants