-
Notifications
You must be signed in to change notification settings - Fork 71
Description
Describe the bug
If I specify a share configuration as follows:
const sharedDeps = {
'@my-org/my-ui-library': { singleton: true },
'@my-org/my-ui-library/foo': { singleton: true },
'@my-org/my-ui-library/bar': { singleton: true },
}
If i was importing from a host or remote, my import statement would look like this, which would work fine:
// app/host-app/index.ts
import foo from '@my-org/my-ui-library/foo'; // works fine
// app/remote/index.ts
import bar from '@my-org/my-ui-library/bar'; // works fine
However lets assume that in my ui library, foo actually has a dependency on bar:
// my-ui-library/src/foo.ts
import bar from '../bar'; // does not work
This relative import is not shared. Instead of importing the loadShare proxy module, the import will just go to the generated chunk. This causes it to get loaded, but not to update the shareScope. As a consequence, when a remote or some other code path tries to load my-ui-library/bar
and checks to see if a shared copy is available, it appears as though it is not and proceeds to load it again.
It looks like the problem is due to the underlying logic itself. In pluginProxySharedModule_preBuild, the shared keys are transformed to regex expressions that are added as aliases. This will match bare specifiers, but not relative imports.
Version
1.7.1
Reproduction
https://github.com/awesome-q/module-federation-example
Relevant log output
Validations
- Read the docs.
- Read the common issues list.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- The provided reproduction is a minimal reproducible example of the bug.