Open tom-sherman opened 2 years ago
I think the only viable route for investigation is to use https://webpack.js.org/concepts/module-federation/#promise-based-dynamic-remotes and using Re.Pack's ChunkManager.loadChunk
API inside.
@zamotany I've tried this but I can't even get the code inside the remote string to execute, just get the same error about react-native not being available for eager consumption.
Any pointers?
I'm wondering if this const { ChunkManager } = import('@callstack/repack/client');
will work at all.
Have you tried regular import import { ChunkManager } from '@callstack/repack/client'
?
@zamotany I just tried that and got a import declaration must be at top level of module
error message, hermes cannot parse the JS with the import there and I guess this JS string isn't run through webpack loaders just injected straight into the bundle.
I've also tried require('@callstack/repack/client')
and get the same earger consumption error from before.
At least I know the code is being injected into the bundle, it's just not being executed and I'm getting the eager consumption error instead. I know this because I've placed a console.log
before the import('@callstack/repack/client')
call and nothing is logged.
Ok, how about assigning ChunkManager
to global
in your entry file before the app runs, and then using global.Chunkmanager
in remotes
?
@zamotany Same error. The code string in remotes
isn't being evaluated at all.
We accomplished something similar in the end using external
and setting ChunkManager
to the __repack__
global. Also needed if(!__webpack_share_scopes__.default) __webpack_init_sharing__('default');
at the top of index.js.
This also unlocked synchronous imports (#7).
Ideally repack should do this work for me wen I supply a URL and/or use the @
syntax.
If I try to use
remotes
andimport()
to reference federated modules I receive the following error:Repro here: https://github.com/tom-sherman/module-federation-repack/commit/b8e6e5c7ae09377209b2096e44c5e05ecb9c73a4
Is it possible to make this work?
My use case is that I want to use regular
import()
s for the benefit you get with TypeScript module declarations, this is not something that's easily achievable withloadComponent
even though they do similar things at runtime.