angular-architects / module-federation-plugin

MIT License
733 stars 202 forks source link

Microsoft/signalr with module federation in angular 16 gives error as below : Uncaught TypeError: Failed to resolve module specifier "module". Relative references must start with either "/", "./", or "../". #348

Open RaneeshTK opened 1 year ago

RaneeshTK commented 1 year ago

main.ts:2 ChunkLoadError: Loading chunk src_bootstrap_ts failed. (missing: http://localhost:4250/src_bootstrap_ts.js) at webpack_require.f.j (main.js:508:28) at ensure chunk:6:1 at Array.reduce () at webpack_require.e (ensure chunk:5:1) at 4913 (main.ts:1:1) at webpack_require (bootstrap:19:1) at main.js:576:88 at webpack_require.O (chunk loaded:23:1) at main.js:577:52

Steps to reproduce
1.Create new angular project in version 16
2. Add  angular architects module federation plugin with custom webpack config for host app
3. Add microsoft/signalR library to the app and import HubConnection from signalR 
4.ng serve the app

Custom-webpack.config.js with ngx-build pllus is as below

const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");

const mf = require("@angular-architects/module-federation/webpack"); const path = require("path"); const share = mf.share;

const sharedMappings = new mf.SharedMappings(); sharedMappings.register( path.join(__dirname, 'tsconfig.json'), [/ mapped paths to share /]);

module.exports = { output: { uniqueName: "testModuleFrederation", publicPath: "auto" }, optimization: { runtimeChunk: false },
resolve: { alias: { ...sharedMappings.getAliases(), } }, experiments: { outputModule: true }, plugins: [ new ModuleFederationPlugin({ library: { type: "module" },

    // For remotes (please adjust)
    // name: "testModuleFrederation",
    // filename: "remoteEntry.js",
    // exposes: {
    //     './Component': './/src/app/app.component.ts',
    // },        

    // For hosts (please adjust)
    // remotes: {
    //     "mfe1": "http://localhost:3000/remoteEntry.js",

    // },

    shared: share({
      "@angular/core": { singleton: true, strictVersion: true, requiredVersion: 'auto' }, 
      "@angular/common": { singleton: true, strictVersion: true, requiredVersion: 'auto' }, 
      "@angular/common/http": { singleton: true, strictVersion: true, requiredVersion: 'auto' }, 
      "@angular/router": { singleton: true, strictVersion: true, requiredVersion: 'auto' },

      ...sharedMappings.getDescriptors()
    })

}),
sharedMappings.getPlugin()

], };

luizluan commented 1 year ago

Same problem here i believe is because of this line on the chunk import { createRequire as __WEBPACK_EXTERNAL_createRequire } from "module";

luizluan commented 1 year ago

Well, I looked into it, and the problem is probably between this specific package and webpack.

luizluan commented 1 year ago

It was fixed in version 8 of the signal r package, this version is still in preview 8.0.0-rc.1.23421.29

timtos commented 1 year ago

@luizluan What was fixed in version 8 of the SignalR package? Do you have some more information about this?

RajathVenkatesh commented 10 months ago

Ran into this exact issue, upgrading @microsoft/signalr to 8.0.0 helped.