MadaraUchiha-314 / nailsmith

A minimal example of how we can do SSR with module federation
MIT License
0 stars 0 forks source link

BFF crashes when trying to loadRemote when remote is served through webpack-dev-server #2

Open MadaraUchiha-314 opened 4 days ago

MadaraUchiha-314 commented 4 days ago

Error:

shell-remote-entry.js:5411
/******/        execOptions.factory.call(module.exports, module, module.exports, execOptions.require);
                                    ^

TypeError: Cannot read properties of undefined (reading 'call')
    at __webpack_require__ (shell-remote-entry.js:5411:32)
    at fn (shell-remote-entry.js:5595:21)
    at shell-remote-entry.js:4647:186
    at /Users/rramakrishnan2/code/github.com/MadaraUchiha-314/nailsmith/packages/bff/dist/index.js:30303:29
    at Module.get (/Users/rramakrishnan2/code/github.com/MadaraUchiha-314/nailsmith/packages/bff/dist/index.js:30282:37)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async RemoteHandler.loadRemote (/Users/rramakrishnan2/code/github.com/MadaraUchiha-314/nailsmith/packages/bff/dist/index.js:31545:37)
    at async /Users/rramakrishnan2/code/github.com/MadaraUchiha-314/nailsmith/packages/bff/dist/index.js:35986:22

The error comes from a call to __webpack_require__ with the moduleId as ./src/app.tsx

MadaraUchiha-314 commented 4 days ago

When BFF server is booted up for the first time, there's a similar call to __webpack_require__ with the moduleId as ./src/app.tsx and that doesn't fail.

Somewhere during revalidate(), __webpack_modules__ is getting cleared and the next call fails.

MadaraUchiha-314 commented 4 days ago

The following entries seem to be removed from __webpack_modules__ after revalidate() has been called:

'./src/app.tsx',
'../../node_modules/react/cjs/react.development.js',
'../../node_modules/react/index.js'

These correspond to the exposed module and './src/app.tsx' and react

Snapshot of __webpack_modules__ before and after.

Before:

[
  '../../node_modules/@module-federation/error-codes/dist/index.cjs.js',
  '../../node_modules/@module-federation/runtime/dist/index.cjs.js',
  '../../node_modules/@module-federation/runtime/dist/polyfills.cjs.js',
  '../../node_modules/@module-federation/runtime/dist/share.cjs.js',
  '../../node_modules/@module-federation/sdk/dist/index.cjs.js',
  '../../node_modules/@module-federation/sdk/dist/polyfills.cjs.js',
  '../../node_modules/@module-federation/webpack-bundler-runtime/dist/constant.cjs.js',
  '../../node_modules/@module-federation/webpack-bundler-runtime/dist/index.cjs.js',
  '../../node_modules/@module-federation/webpack-bundler-runtime/dist/polyfills.cjs.js',
  '../../node_modules/webpack/hot/dev-server.js',
  '../../node_modules/webpack/hot/emitter.js',
  '../../node_modules/webpack/hot/log-apply-result.js',
  '../../node_modules/webpack/hot/log.js',
  'webpack/container/entry/shell_app',
  'events',
  'os',
  'process',
  'tty',
  '../../node_modules/@module-federation/node/dist/src/runtimePlugin.js',
  '../../node_modules/isomorphic-rslog/dist/node/index.cjs',
  './node_modules/.federation/entry.cb95599fec437b225c6731bbaa287f03.js',
  './src/app.tsx',
  '../../node_modules/react/cjs/react.development.js',
  '../../node_modules/react/index.js'
]

After:

[
  '../../node_modules/@module-federation/error-codes/dist/index.cjs.js',
  '../../node_modules/@module-federation/runtime/dist/index.cjs.js',
  '../../node_modules/@module-federation/runtime/dist/polyfills.cjs.js',
  '../../node_modules/@module-federation/runtime/dist/share.cjs.js',
  '../../node_modules/@module-federation/sdk/dist/index.cjs.js',
  '../../node_modules/@module-federation/sdk/dist/polyfills.cjs.js',
  '../../node_modules/@module-federation/webpack-bundler-runtime/dist/constant.cjs.js',
  '../../node_modules/@module-federation/webpack-bundler-runtime/dist/index.cjs.js',
  '../../node_modules/@module-federation/webpack-bundler-runtime/dist/polyfills.cjs.js',
  '../../node_modules/webpack/hot/dev-server.js',
  '../../node_modules/webpack/hot/emitter.js',
  '../../node_modules/webpack/hot/log-apply-result.js',
  '../../node_modules/webpack/hot/log.js',
  'webpack/container/entry/shell_app',
  'events',
  'os',
  'process',
  'tty',
  '../../node_modules/@module-federation/node/dist/src/runtimePlugin.js',
  '../../node_modules/isomorphic-rslog/dist/node/index.cjs',
  './node_modules/.federation/entry.cb95599fec437b225c6731bbaa287f03.js'
]
MadaraUchiha-314 commented 4 days ago

Manually checked the diff b/w the remote entries for shell after multiple reloads. The only change is in the hash.

5502c5502
< /******/      __webpack_require__.h = () => ("114050193a9b2d6baa01")
---
> /******/      __webpack_require__.h = () => ("fd3d596472defec70cae")