core icon indicating copy to clipboard operation
core copied to clipboard

import: false not supported in the new runtime apis

Open MadaraUchiha-314 opened this issue 1 year ago • 9 comments

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.

MadaraUchiha-314 avatar Jan 25 '24 06:01 MadaraUchiha-314

Do you have a sample repo that demonstrates the issue?

ScriptedAlchemy avatar Jan 25 '24 23:01 ScriptedAlchemy

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.

ScriptedAlchemy avatar Jan 26 '24 00:01 ScriptedAlchemy

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 avatar Feb 07 '24 09:02 2heal1

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 avatar Feb 07 '24 09:02 2heal1

@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.

import-false-not-working

MadaraUchiha-314 avatar Feb 07 '24 22:02 MadaraUchiha-314

Stale issue message

github-actions[bot] avatar Apr 08 '24 15:04 github-actions[bot]

not stale.

MadaraUchiha-314 avatar Apr 08 '24 16:04 MadaraUchiha-314

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

MadaraUchiha-314 avatar Apr 25 '24 01:04 MadaraUchiha-314

https://github.com/module-federation/core/pull/2330 ??

MadaraUchiha-314 avatar Apr 25 '24 17:04 MadaraUchiha-314

Stale issue message

github-actions[bot] avatar Jun 25 '24 15:06 github-actions[bot]