英文:
Module Federation with NX Unsatisfied Version React Icons
问题
I'm having an issue with Module Federation in my project.
我在项目中遇到了模块联邦的问题。
I have the following module-federation.config.js
in my shell
app:
我在我的shell
应用程序中有以下module-federation.config.js
:
Now app-1
uses react-icons
and app-2
does not.
现在app-1
使用了react-icons
,而app-2
没有。
If I run app-2
standalone it works with no problems and if I run my shell
app and render app-1
inside that it also works fine.
如果我单独运行app-2
,它可以正常运行,如果我运行我的shell
应用程序并在其中渲染app-1
,它也可以正常工作。
However, when I try to run app-1
standalone, it throws the following error:
然而,当我尝试单独运行app-1
时,它会抛出以下错误:
Unsatisfied version 0 from monolith-deployment of shared singleton module react-icons (required ^4.4.0)
无法满足共享单例模块react-icons(需要^4.4.0)的monolith-deployment版本0
I'm sure I'm missing something basic, but I'm just too new at module-federation to figure it out.
我确信我错过了一些基础知识,但我对模块联邦还不够熟悉,无法弄清楚。
Here's a warning I get, but I'm not sure what to do with it:
这是一个警告,但我不确定该怎么处理它:
WARNING in shared module react-icons -> /workspaces/my-repo/node_modules/react-icons/lib/esm/index.js
警告:共享模块react-icons -> /workspaces/my-repo/node_modules/react-icons/lib/esm/index.js
No version specified and unable to automatically determine one. No version in description file (usually package.json). Add version to description file /workspaces/my-repo/node_modules/react-icons/lib/package.json, or manually specify version in shared config.
没有指定版本,无法自动确定版本。在描述文件(通常是package.json)中添加版本到/workspaces/my-repo/node_modules/react-icons/lib/package.json,或在共享配置中手动指定版本。
英文:
I'm having an issue with Module Federation in my project.
I have the following module-federation.config.js
in my shell
app:
/**
* @type {import('@nrwl/devkit').ModuleFederationConfig}
**/
const moduleFederationConfig = {
name: 'shell',
remotes: ['app-1', 'app-2'],
shared: (name, config) => {
// We want react-icons to be tree shaken, and bundled into each host/remote separately.
if (name === 'react-icons') {
return false;
}
return undefined;
},
};
module.exports = moduleFederationConfig;
Now app-1
uses react-icons
and app-2
does not. If I run app-2
standalone it works with no problems and if I run my shell
app and render app-1
inside that it also works fine.
However, when I try to run app-1
standalone, it throws the following error:
> Unsatisfied version 0 from monolith-deployment of shared singleton module react-icons (required ^4.4.0)
I'm sure I'm missing something basic, but I'm just to new at module-federation to figure it out.
Here's a warning I get, but I'm not sure what to do with it:
> WARNING in shared module react-icons -> /workspaces/my-repo/node_modules/react-icons/lib/esm/index.js
No version specified and unable to automatically determine one. No version in description file (usually package.json). Add version to description file /workspaces/my-repo/node_modules/react-icons/lib/package.json, or manually specify version in shared config.
答案1
得分: 0
问题在于此帖子发布时使用的 nx
版本存在一个从 v15.8.6
持续到 v15.9.2
的错误。
v15.9.3
修复了此问题。
解决方案
将 nx
更新到最新版本,或者至少避免使用版本 15.8.6
到 15.9.2
。
英文:
The issue is that the version of nx
used at the time this was posted had a bug in it that lasted from v15.8.6
all the way through to v15.9.2
.
v15.9.3
fixes it.
Solution
Update nx
to the latest version, or at least avoid using versions 15.8.6
-15.9.2
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论