最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

micro frontend - Module Federation Error: Uncaught SyntaxError: Unexpected token 'export' (at remoteEntry.js:397

programmeradmin0浏览0评论

So I am using webpack 5 to demonstrate Module Federation in Angular 19. For this I have created a 'host-app' and a 'remote-app' and done all the required configurations related to webpack.config.js in both. My 'remoteEntry.js' file is getting generated as expected but Angular is not able read the keywords like 'export' in the 'remoteEntry.js' file. The reason behind this is likely to be related to the 'remoteEntry.js' being read as text javascript file rather than a type="module". I tried all the things but still unable to resolve this issue. Please find below code snippets for the reference:

ERROR Screenshot:

remote-app webpack.config.js

host-app webpack.config.js

app.routes.ts

tsconfig.json

So I am using webpack 5 to demonstrate Module Federation in Angular 19. For this I have created a 'host-app' and a 'remote-app' and done all the required configurations related to webpack.config.js in both. My 'remoteEntry.js' file is getting generated as expected but Angular is not able read the keywords like 'export' in the 'remoteEntry.js' file. The reason behind this is likely to be related to the 'remoteEntry.js' being read as text javascript file rather than a type="module". I tried all the things but still unable to resolve this issue. Please find below code snippets for the reference:

ERROR Screenshot:

remote-app webpack.config.js

host-app webpack.config.js

app.routes.ts

tsconfig.json

Share Improve this question asked Mar 6 at 11:59 Santosh ThakurSantosh Thakur 1
Add a comment  | 

1 Answer 1

Reset to default 0

I had an error like this. If you print your config you'll see, that "library" property of ModuleFederationPlugin is { type: "module" }. I changed it to { type: "var", name: "nameOfYourApp" } and this action fixed the error. Something like this:

mfConfig.plugins[0]._options.library = {type: 'var', name: 'name'}
发布评论

评论列表(0)

  1. 暂无评论