core
core copied to clipboard
import: false not supported in the new runtime apis
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
- [X] Read the Contributing Guidelines.
- [X] Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
Do you have a sample repo that demonstrates the issue?
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.
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 .
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.
@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: https://github.com/MadaraUchiha-314/rollup-plugin-module-federation/pull/35
-
project-a: Shares and provides
react
-
project-b: Declares react as
import: false
-
project-a consumes project-b
-
Code: https://github.com/MadaraUchiha-314/rollup-plugin-module-federation/blob/supporting-import-false/packages/examples/project-a/src/index.js#L5
-
Deployed URL: https://rollup-plugin-module-federation-pro-git-232268-madarauchiha-314.vercel.app/rollup/esm/
-
Below image shows the issue, where project-b is referencing
react
and its coming as null.
Stale issue message
not stale.
@ScriptedAlchemy @2heal1 Is this complete by any chance ?
https://github.com/module-federation/core/pull/2330 ??
Stale issue message