question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

module federation HMR on host

See original GitHub issue

Current Behavior

host app HMR is not working and I need to reload the page by myself. but remote app HMR is working as expected (inside the host app).

Expected Behavior

when changing the code in the host app, it should reload the app.

Steps to Reproduce

just look at my configurations:

for the host project.json (I’m using nx server):

"serve": {
  "executor": "@nrwl/react:module-federation-dev-server",
  "defaultConfiguration": "development",
  "options": {
    "buildTarget": "client:build",
    "hmr": true,
    "port": 4200
  },
  "configurations": {
    "development": {
      "buildTarget": "client:build:development",
      "open": true,
      "watch": true,
      "liveReload": true
    },
    "production": {
      "buildTarget": "client:build:production",
      "hmr": false
    }
  }
}

and this is in the remote project.json

"serve": {
  "executor": "@nrwl/react:module-federation-dev-server",
  "defaultConfiguration": "development",
  "options": {
    "buildTarget": "assets:build",
    "hmr": true,
    "port": 4201
  },
  "configurations": {
    "development": {
      "buildTarget": "assets:build:development"
    },
    "production": {
      "buildTarget": "assets:build:production",
      "hmr": false
    }
  }
}

Failure Logs

I see this warning in the console. I’m not sure if its related

(missing: http://localhost:4200/polyfills.2c951a6de4399979.hot-update.mjs)
    at http://localhost:4200/polyfills.js:21576:25
    at new Promise (<anonymous>)
    at loadUpdateChunk (http://localhost:4200/polyfills.js:21571:19)
    at http://localhost:4200/polyfills.js:22031:28
    at Array.forEach (<anonymous>)
    at __webpack_require__.hmrC.jsonp (http://localhost:4200/polyfills.js:22026:21)
    at http://localhost:4200/polyfills.js:21054:46
    at Array.reduce (<anonymous>)
    at http://localhost:4200/polyfills.js:21050:54

Environment

   Node : 17.3.0
   OS   : darwin x64
   npm  : 8.3.0
   
   nx : 14.4.2
   @nrwl/angular : Not Found
   @nrwl/cypress : 14.4.2
   @nrwl/detox : Not Found
   @nrwl/devkit : 14.4.2
   @nrwl/eslint-plugin-nx : 14.4.2
   @nrwl/express : Not Found
   @nrwl/jest : 14.4.2
   @nrwl/js : 14.4.2
   @nrwl/linter : 14.4.2
   @nrwl/nest : Not Found
   @nrwl/next : Not Found
   @nrwl/node : Not Found
   @nrwl/nx-cloud : Not Found
   @nrwl/nx-plugin : Not Found
   @nrwl/react : 14.4.2
   @nrwl/react-native : Not Found
   @nrwl/schematics : Not Found
   @nrwl/storybook : 14.4.2
   @nrwl/web : 14.4.2
   @nrwl/workspace : 14.4.2
   typescript : 4.7.4
   ---------------------------------------
   Community plugins:

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:13

github_iconTop GitHub Comments

2reactions
ryansevillacommented, Oct 24, 2022

What ended up fixing it for me was also removing the “styles” attribute from the project.json as well. I made two separate build processes, one for local and one for prod, the local one removes polyfills and styles, the prod one keeps them.

1reaction
jamieatmirzacommented, Oct 4, 2022

I managed to fix it by removing the "polyfills" from the build target for development

Could you paste an example? Also, could this introduce any side effects?

@usyyy I moved the polyfills in the host apps project.json into the production configuration. e.g.

    "build": {
      "executor": "@nrwl/webpack:webpack",
      "outputs": ["{options.outputPath}"],
      "defaultConfiguration": "production",
      "options": {
        "compiler": "babel",
        "outputPath": "dist/apps/host",
        "index": "apps/host/src/index.html",
        "baseHref": "/",
        "main": "apps/host/src/main.ts",
        "tsConfig": "apps/host/tsconfig.app.json",
        "assets": [
          "apps/host/src/favicon.ico"
        ],
        "styles": [],
        "scripts": [],
        "webpackConfig": "apps/host/webpack.config.js",
        "postcssConfig": "apps/host/postcss.config.js"
      },
      "configurations": {
        "development": {
          "extractLicenses": false,
          "optimization": false,
          "sourceMap": true,
          "vendorChunk": true
        },
        "production": {
          "polyfills": "apps/host/src/polyfills.ts",
          "fileReplacements": [
            {
              "replace": "apps/host/src/environments/environment.ts",
              "with": "apps/host/src/environments/environment.prod.ts"
            }
          ],
          "optimization": true,
          "outputHashing": "all",
          "sourceMap": false,
          "namedChunks": false,
          "extractLicenses": true,
          "vendorChunk": false,
          "webpackConfig": "apps/host/webpack.config.prod.js"
        }
      }
    },
Read more comments on GitHub >

github_iconTop Results From Across the Web

Federated Module Reloading. - Medium
We're passionate about making Module Federation easier and more enjoyable to use. Based on user feedback, we knew FMR was the perfect place...
Read more >
Enabling Live Reload in Module Federated CRA - Raj Rajhans
Recently I had work on getting hot reload to work in a module ... The issue is that currently HMR doesn't work with...
Read more >
nx react module federation hot reload - Stack Overflow
I'm using module federation with nx and want to enable HMR. I applied the hmr: true option in both project.json files. (for the...
Read more >
Hot Module Replacement - webpack
HMR is not intended for use in production, meaning it should only be used in development. See the building for production guide for...
Read more >
Module federation - Notes
Module federation is about managing different physical parts of the application(s) in runtime. We already looked at this problem in code splitting chapter....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found