Replies: 3 comments 1 reply
-
Expected, because you don't use them and don't export, I can't help without full configuration or minimum reproducible test repo using github |
Beta Was this translation helpful? Give feedback.
-
@alexander-akait, @ScriptedAlchemy sorry,my code was Incomplete.I used the export constant.I can't provide reproducible test repo, but something I've discovered. I have two repository, running with production. they have same webpack version. main-appThe main application,load remoteEntry from sub-app. sub-appAnother application, use moduleFederation expose module. constant.tsexport const a = 1;
export const b = 2;
export const c = 3; remote.jsimport { a } from '.'
(() => {
console.log(a)
})() index.jsimport { b, c } from '.'
(() => {
console.log(b,c)
})() webpack.config.jsmodule.export = {
entry: index.js,
output: {
path: ...
filename: ...
chunkFilename: ...,
publicPath: ...,
clean: true,
library: ...,
libraryTarget: 'window',
},
optimization: {
minimizer: [
new TerserWebpackPlugin({
parallel: true
}),
],
splitChunks: {
chunks: 'all',
}
},
plugins: [
new ModuleFederationPlugin({
name: 'subApp',
filename: 'remoteEntry.js',
exposes: {
'./remote': path.resolve(
__dirname,
'./remote.js'
),
},
]
} moduleFederation chunk bundled const when I visit // The module cache
var __webpack_module_cache__ = {};
// The require function
function __webpack_require__(moduleId) {
// Check if module is in cache
var cachedModule = __webpack_module_cache__[moduleId];
if (cachedModule !== undefined) {
return cachedModule.exports;
}
// Create a new module (and put it into the cache)
var module = __webpack_module_cache__[moduleId] = {
id: moduleId,
loaded: false,
exports: {}
};
// Execute the module function
__webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
// Flag the module as loaded
module.loaded = true;
// Return the exports of the module
return module.exports;
}
I add the var webpackJsonpCallback = function(parentChunkLoadingFunction, data) {
var chunkIds = data[0];
var moreModules = data[1];
var runtime = data[2];
var moduleId, chunkId, i = 0;
if(chunkIds.some(function(id) { return installedChunks[id] !== 0; })) {
for(moduleId in moreModules) {
if(__webpack_require__.o(moreModules, moduleId)) {
__webpack_require__.m[moduleId] = moreModules[moduleId];
}
}
// loaded moduleFederation chunk will jump in this,and throw error.
if(runtime) var result = runtime(__webpack_require__);
}
//...
} I set finally, i can switch application with no error. |
Beta Was this translation helpful? Give feedback.
-
I've run into this with runtimeChunk:single You can do something like this. To solve it. In the enhanced package we fixed chunk split issues and multiple runtime chunks. Then under the hood we generate another remote with runtime:undefined and use a runtime plugin in the new api to tell remotes to switch to the single runtime chunk remotes if a remote attempts to load the container of the host otherwise it loads the runtime:false one with its own module graph. module-federation/module-federation-examples#3847 |
Beta Was this translation helpful? Give feedback.
-
Bug report
What is the current behavior?
ModuleFederation chunk conflict with Entry chunk
If the current behavior is a bug, please provide the steps to reproduce.
I set
main.js
to entry and exposeremote.js
to ModuleFederation.They will use same moduleId to generate code in chunks.
But
remote.js
chunks will haven't exportsb
andc
because of tree-shaking.So, if loaded remoteEntry.js first, webpack runtime will use moduleId to cacheModule, and then loaded
main.js
will can't find constantb
orc
.What is the expected behavior?
It shouldn't have same moduleId
Other relevant information:
webpack version: 5.74.0
Node.js version: v16.18.1
Operating System: mac os
Additional tools:
Beta Was this translation helpful? Give feedback.
All reactions