Giter Club home page Giter Club logo

universe's People

Contributors

2heal1 avatar apehead avatar brunos3d avatar caiorolla avatar coly010 avatar dependabot[bot] avatar dmcgoughpax8 avatar elado avatar enochgao avatar fyodorovandrei avatar hongkiulam avatar icelattefull avatar ilteoood avatar jacob-ebey avatar jherr avatar kinbaum avatar kyletsang avatar lexasq avatar maximilianklein avatar nodkz avatar nyqykk avatar omfgnuts avatar pavandv avatar ranshamay avatar renovate[bot] avatar russellcanfield avatar scriptedalchemy avatar semantic-release-bot avatar valorkin avatar zhoushaw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

universe's Issues

https support

Found a TODO comment on line 30 of file node-plugin/streaming/loadScript.js

Does react refresh work?

Checking with the community, does this plugin work in next dev mode?

When trying It on larger repos, i run into react refresh related problems.

Not able to set up working example based on README instructions

First of all, this is awesome and thanks so much for your contribution! I've been trying to set up a working example locally for the past couple of days - noticing we went from 2.0 to 2.2 - yet either way I end up in a situation where both apps compile just fine but the consuming app has some 404s on some bundles and fails to load the federated component from the remote.

I troubleshooted all options including naming, ports, etc.

I wonder if you could provide more detailed instructions on setting up:

  • covering a scenario from complete scratch, including every single bash command as trivial as creating or entering folders, also creating the nextJS apps themselves from scratch
  • being MORE explicit and specific about which addition of code/config goes EXACTLY in which file, with path and full filename, perhaps showing the added code in more context
  • provide an updated repo (and keep it up to date) that showcases a stable working example based on latest framework versions and dependencies

Both frameworks and dependencies are moving incredibly fast in today's JS ecosystem. Without explicit, verified instructions a lot of folks may be blocked by running into trivial issues. Much thanks!

should use vm.runInThisContext instead of eval

Found a TODO comment on line 25 of file node-plugin/streaming/NodeRuntime.js

I already do this when in the webpack runtime and loading federated chunks, but this needs to be done for the "last mile" where the host needs to load the remote container in the first place.

Would it be possible to use the webpack_require function itself?

In browser we use webpack_require.l() to load scripts, for node we could use webpack_require.readFile?

SSR remote updates are ignored

When running SSR with module federation we noticed that the next.js server never updates the remote dependencies, e.g. when we replace the files (or even removing them does still use the old component). This sadly can lead to out of sync SSR and clients.

I looked a bit into what happens and there are multiple reasons for that.

  1. The require from withModuleFederation caches the remoteEntry.js files (but the require is never called multiple times because
  2. the webpack_runtime caches all dependencies without any means of clearing the cache or removing specific cache-items (I cold not find anything in webpack that would help me here)
  3. I also checked if the get in withModuleFederation could be used, but it is also never called twice for one remote.

The only method that I currently know that works is restarting the nextjs server completely.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • chore(deps): update dependency msw to v1.3.3
  • chore(deps): update dependency postcss-custom-properties to v13.3.6
  • chore(deps): update dependency tailwindcss to v3.4.3
  • chore(deps): update react monorepo (@types/react, @types/react-dom)
  • fix(deps): update dependency adm-zip to v0.5.12
  • fix(deps): update dependency adm-zip to v0.5.12
  • fix(deps): update dependency antd to v4.24.16
  • fix(deps): update dependency axios to v1.6.8
  • fix(deps): update dependency axios to v1.6.8
  • fix(deps): update dependency next to v14.1.4
  • fix(deps): update dependency rambda to v9.1.1
  • fix(deps): update dependency react-router-dom to v6.22.3
  • fix(deps): update dependency sharp to v0.33.3
  • fix(deps): update dependency typedoc to v0.25.12
  • chore(deps): update dependency @builder.io/partytown to v0.10.1
  • chore(deps): update dependency @builder.io/qwik to v1.5.1
  • chore(deps): update dependency @builder.io/qwik-city to v1.5.1
  • chore(deps): update dependency @modern-js-app/eslint-config to v2.48.4
  • chore(deps): update dependency @modern-js/app-tools to v2.48.4
  • chore(deps): update dependency @modern-js/eslint-config to v2.48.4
  • chore(deps): update dependency @modern-js/tsconfig to v2.48.4
  • chore(deps): update dependency @node-rs/jieba to v1.10.0
  • chore(deps): update dependency @testing-library/react to v14.2.2
  • chore(deps): update dependency @types/node to ~16.18.0
  • chore(deps): update dependency cypress to v13.7.1
  • chore(deps): update dependency eslint to v8.57.0 (eslint, @types/eslint)
  • chore(deps): update dependency eslint-plugin-qwik to v1.5.1
  • chore(deps): update dependency eslint-plugin-react to v7.34.1
  • chore(deps): update dependency lint-staged to ~13.3.0
  • chore(deps): update dependency mammoth to v1.7.1
  • chore(deps): update dependency node to v18.20.0 (node, @types/node)
  • chore(deps): update dependency open to v10.1.0
  • chore(deps): update dependency prettier-eslint to v16.3.0
  • chore(deps): update dependency qwik-speak to v0.22.0
  • chore(deps): update dependency typescript to v5.4.3
  • chore(deps): update dependency verdaccio to v5.30.2
  • chore(deps): update dependency vite-tsconfig-paths to v4.3.2
  • chore(deps): update dependency wast-loader to v1.12.1
  • chore(deps): update dependency webpack to v5.91.0
  • chore(deps): update dependency webpack to v5.91.0
  • chore(deps): update github/issue-labeler action to v3.4
  • chore(deps): update nrwl monorepo to v17.3.2 (@nx/cypress, @nx/devkit, @nx/esbuild, @nx/eslint-plugin, @nx/express, @nx/jest, @nx/js, @nx/linter, @nx/next, @nx/node, @nx/react, @nx/rollup, @nx/storybook, @nx/vite, @nx/web, @nx/webpack, nx)
  • chore(deps): update swc monorepo (@swc-node/register, @swc/cli, @swc/core, @swc/helpers, @swc/jest, swc-loader)
  • fix(deps): update dependency @modern-js/runtime to v2.48.4
  • fix(deps): update dependency core-js to v3.36.1
  • fix(deps): update dependency enhanced-resolve to v5.16.0
  • fix(deps): update dependency unplugin to v1.10.1
  • fix(deps): update dependency unplugin to v1.10.1
  • chore(deps): update actions/cache action to v4
  • chore(deps): update commitlint monorepo to v19 (major) (@commitlint/cli, @commitlint/config-conventional, @commitlint/config-nx-scopes, @commitlint/cz-commitlint)
  • chore(deps): update dependency @jscutlery/semver to v5
  • chore(deps): update dependency copy-webpack-plugin to v12
  • chore(deps): update dependency eslint-plugin-simple-import-sort to v12
  • chore(deps): update dependency husky to v9
  • chore(deps): update dependency lint-staged to v15
  • chore(deps): update dependency ngx-deploy-npm to v8
  • chore(deps): update dependency nx-cloud to v18
  • chore(deps): update dependency postcss-import to v16
  • chore(deps): update dependency prettier to v3.2.5
  • chore(deps): update dependency qwik-nx to v2
  • chore(deps): update dependency rimraf to v5
  • chore(deps): update dependency stopword to v3
  • chore(deps): update dependency strip-ansi to v7
  • chore(deps): update dependency vue-tsc to v2
  • chore(deps): update nextjs monorepo to v14 (major) (eslint-config-next, next)
  • chore(deps): update nrwl monorepo (major) (@nx/cypress, @nx/devkit, @nx/esbuild, @nx/eslint-plugin, @nx/express, @nx/jest, @nx/js, @nx/linter, @nx/next, @nx/node, @nx/react, @nx/rollup, @nx/rspack, @nx/storybook, @nx/vite, @nx/web, @nx/webpack, nrwl/nx-set-shas, nx)
  • chore(deps): update semantic-release monorepo (major) (@semantic-release/github, @semantic-release/npm)
  • chore(deps): update storybook monorepo to v8 (major) (@storybook/addon-essentials, @storybook/builder-webpack5, @storybook/core-common, @storybook/core-server, @storybook/node-logger, @storybook/react)
  • chore(deps): update typescript-eslint monorepo to v7 (major) (@typescript-eslint/eslint-plugin, @typescript-eslint/parser)
  • fix(deps): update dependency acorn to v8
  • fix(deps): update dependency buffer to v6
  • fix(deps): update dependency chalk to v5
  • fix(deps): update dependency eslint-scope to v8
  • fix(deps): update dependency fs-extra to v11
  • fix(deps): update dependency rambda to v9
  • fix(deps): update dependency react to v18
  • fix(deps): update dependency schema-utils to v4
  • fix(deps): update dependency semver to v7
  • fix(deps): update dependency tsup to v8
  • fix(deps): update dependency undici to v6

Warning

Renovate failed to look up the following dependencies: Failed to look up npm package @scoped/package, Failed to look up npm package shared2, Failed to look up github-tags package foo/bar, Failed to look up npm package shared19.

Files affected: packages/enhanced/test/configCases/sharing/consume-module-ignore-warnings/package.json, packages/enhanced/test/configCases/sharing/consume-module/package.json, packages/enhanced/test/configCases/sharing/consume-multiple-versions-ignore-warnings/package.json, packages/enhanced/test/configCases/sharing/consume-multiple-versions/package.json


Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

github-actions
.github/workflows/build-and-test.yml
  • actions/checkout v3
  • actions/setup-node v3
  • nrwl/nx-set-shas v3
.github/workflows/deploy-website.yml
  • styfle/cancel-workflow-action 0.12.1
  • actions/checkout v4@b4ffde65f46336ab88eb53be808477a3936bae11
  • actions/cache v3
  • actions/checkout v4@b4ffde65f46336ab88eb53be808477a3936bae11
  • actions/cache v3
  • actions/checkout v4@b4ffde65f46336ab88eb53be808477a3936bae11
  • actions/cache v3
  • nelonoel/branch-name v1.0.1
.github/workflows/issue-close-require.yml
  • actions-cool/issues-helper v3
.github/workflows/issue-labeled.yml
  • actions-cool/issues-helper v3
  • actions-cool/issues-helper v3
.github/workflows/pr-label.yaml
  • github/issue-labeler v3.3
.github/workflows/release-pull-request.yml
  • actions/setup-node v3
  • web-infra-dev/actions v2
.github/workflows/release.yml
  • actions/checkout v3
  • actions/setup-node v3
  • web-infra-dev/actions v2
  • actions/checkout v3
  • actions/setup-node v3
  • web-infra-dev/actions v2
.github/workflows/stale.yml
  • actions/stale v8
npm
apps/3000-home/package.json
  • acorn 7.4.1
  • antd 4.24.15
  • buffer 5.7.1
  • chrome-trace-event 1.0.3
  • encoding 0.1.13
  • enhanced-resolve 5.15.0
  • eslint-scope 7.2.2
  • eventemitter3 5.0.1
  • events 3.3.0
  • fast-glob 3.3.2
  • js-cookie 3.0.5
  • lodash 4.17.21
  • next 14.1.2
  • node-fetch 2.7.0
  • react 18.2.0
  • react-dom 18.2.0
  • schema-utils 3.3.0
  • semver 6.3.1
  • styled-jsx 5.1.2
  • tapable 2.2.1
  • terser-webpack-plugin 5.3.10
  • typescript 5.3.3
  • upath 2.0.1
  • url 0.11.3
  • util 0.12.5
  • webpack-sources 3.2.3
apps/3001-shop/package.json
  • acorn 7.4.1
  • antd 4.24.15
  • buffer 5.7.1
  • chrome-trace-event 1.0.3
  • encoding 0.1.13
  • enhanced-resolve 5.15.0
  • eslint-scope 7.2.2
  • eventemitter3 5.0.1
  • events 3.3.0
  • fast-glob 3.3.2
  • lodash 4.17.21
  • next 14.1.2
  • node-fetch 2.7.0
  • react 18.2.0
  • react-dom 18.2.0
  • schema-utils 3.3.0
  • semver 6.3.1
  • styled-jsx 5.1.2
  • tapable 2.2.1
  • terser-webpack-plugin 5.3.10
  • typescript 5.3.3
  • upath 2.0.1
  • url 0.11.3
  • util 0.12.5
  • webpack-sources 3.2.3
apps/3002-checkout/package.json
  • acorn 7.4.1
  • antd 4.24.15
  • buffer 5.7.1
  • chrome-trace-event 1.0.3
  • encoding 0.1.13
  • enhanced-resolve 5.15.0
  • eslint-scope 7.2.2
  • eventemitter3 5.0.1
  • events 3.3.0
  • fast-glob 3.3.2
  • lodash 4.17.21
  • next 14.1.2
  • node-fetch 2.7.0
  • react 18.2.0
  • react-dom 18.2.0
  • schema-utils 3.3.0
  • semver 6.3.1
  • styled-jsx 5.1.2
  • tapable 2.2.1
  • terser-webpack-plugin 5.3.10
  • typescript 5.3.3
  • upath 2.0.1
  • url 0.11.3
  • util 0.12.5
  • webpack-sources 3.2.3
apps/manifest-demo/3008-webpack-host/package.json
  • antd 4.24.15
  • @pmmmwh/react-refresh-webpack-plugin 0.5.11
  • react-refresh 0.14.0
apps/manifest-demo/3009-webpack-provider/package.json
  • antd 4.24.14
  • @pmmmwh/react-refresh-webpack-plugin 0.5.11
  • react-refresh 0.14.0
apps/manifest-demo/3010-rspack-provider/package.json
  • antd 4.24.15
  • @pmmmwh/react-refresh-webpack-plugin 0.5.11
  • react-refresh 0.14.0
  • @rspack/plugin-react-refresh 0.5.9
apps/manifest-demo/3011-rspack-manifest-provider/package.json
  • lodash 4.17.21
  • @pmmmwh/react-refresh-webpack-plugin 0.5.11
  • react-refresh 0.14.0
  • @rspack/plugin-react-refresh 0.5.9
apps/manifest-demo/3012-rspack-js-entry-provider/package.json
  • lodash 4.17.21
  • @pmmmwh/react-refresh-webpack-plugin 0.5.11
  • react-refresh 0.14.0
  • @rspack/plugin-react-refresh 0.5.9
apps/modernjs/package.json
  • @modern-js/runtime 2.46.1
  • react ~18.2.0
  • react-dom ~18.2.0
  • @modern-js/app-tools 2.46.1
  • @modern-js/eslint-config 2.46.1
  • @modern-js/tsconfig 2.46.1
  • @modern-js-app/eslint-config 2.46.1
  • typescript ~5.0.4
  • @types/jest ~29.5.0
  • @types/node ~16.11.7
  • @types/react ~18.2.0
  • @types/react-dom ~18.2.0
  • lint-staged ~13.1.0
  • prettier ~2.8.1
  • rimraf ~3.0.2
  • node >=16.18.1
apps/node-host-e2e/package.json
apps/node-host/package.json
apps/node-local-remote/package.json
apps/node-remote/package.json
apps/react-ts-host/package.json
  • @pmmmwh/react-refresh-webpack-plugin 0.5.11
  • react-refresh 0.14.0
apps/react-ts-remote/package.json
  • react-refresh 0.14.0
  • file-loader 6.2.0
apps/reactRemoteUI/package.json
apps/reactStorybook/package.json
apps/runtime-demo/3005-runtime-host/package.json
  • antd 4.24.15
  • @pmmmwh/react-refresh-webpack-plugin 0.5.11
  • react-refresh 0.14.0
apps/runtime-demo/3006-runtime-remote/package.json
  • antd 4.24.15
  • @pmmmwh/react-refresh-webpack-plugin 0.5.11
  • react-refresh 0.14.0
apps/runtime-demo/3007-runtime-remote/package.json
  • antd 4.24.15
  • @pmmmwh/react-refresh-webpack-plugin 0.5.11
  • react-refresh 0.14.0
apps/website/package.json
package.json
  • adm-zip 0.5.10
  • ansi-colors 4.1.3
  • antd 4.24.15
  • axios 1.6.7
  • core-js 3.34.0
  • encoding ^0.1.13
  • express 4.19.2
  • fast-glob 3.3.2
  • lodash.get 4.4.2
  • next 14.1.2
  • rambda 7.5.0
  • react 18.2.0
  • react-dom 18.2.0
  • react-router-dom 6.22.0
  • regenerator-runtime 0.14.1
  • sharp ^0.33.2
  • tapable 2.2.1
  • tsup 7.2.0
  • typedoc 0.25.8
  • undici 5.28.3
  • unplugin 1.9.0
  • terser-webpack-plugin ^5.3.10
  • @antora/cli 3.1.5
  • @antora/lunr-extension 1.0.0-alpha.8
  • @antora/site-generator 3.1.7
  • @asciidoctor/core 3.0.4
  • @asciidoctor/tabs 1.0.0-beta.6
  • @babel/core ^7.23.3
  • @babel/plugin-transform-react-jsx 7.23.4
  • @babel/preset-react ^7.14.5
  • @builder.io/partytown 0.8.1
  • @builder.io/qwik 1.3.1
  • @builder.io/qwik-city 1.3.2
  • @changesets/cli ^2.27.1
  • @commitlint/cli ^17.7.2
  • @commitlint/config-conventional 17.8.1
  • @commitlint/config-nx-scopes ^17.6.4
  • @commitlint/cz-commitlint ^17.7.2
  • @dqbd/tiktoken 1.0.13
  • @fontsource/roboto 5.0.12
  • @fontsource/roboto-mono 5.0.17
  • @jscutlery/semver 4.2.0
  • @node-rs/jieba 1.9.2
  • @nx/cypress 17.2.8
  • @nx/devkit 17.2.8
  • @nx/esbuild 17.2.8
  • @nx/eslint-plugin 17.2.8
  • @nx/express 17.2.8
  • @nx/jest 17.2.8
  • @nx/js 17.2.8
  • @nx/linter 17.2.8
  • @nx/next 17.2.8
  • @nx/node 17.2.8
  • @nx/react 17.2.8
  • @nx/rollup 17.2.8
  • @nx/storybook 17.2.8
  • @nx/vite 17.2.8
  • @nx/web 17.2.8
  • @nx/webpack 17.2.8
  • @nx/rspack 17.2.8
  • @rspack/dev-server ^0.5.4
  • @rspack/core ^0.5.4
  • @pmmmwh/react-refresh-webpack-plugin 0.5.11
  • @rollup/plugin-alias 5.1.0
  • @rollup/plugin-replace 5.0.5
  • @semantic-release/changelog ^6.0.3
  • @semantic-release/exec ^6.0.3
  • @semantic-release/git ^10.0.1
  • @semantic-release/github ^9.2.1
  • @semantic-release/npm ^11.0.0
  • @storybook/addon-essentials 7.6.17
  • @storybook/builder-webpack5 7.6.17
  • @storybook/core-common 7.6.17
  • @storybook/core-server 7.6.17
  • @storybook/manager-webpack5 6.5.16
  • @storybook/node-logger 7.6.17
  • @storybook/react 7.6.17
  • @svgr/webpack 8.1.0
  • @swc-node/register 1.6.8
  • @swc/cli 0.1.63
  • @swc/core 1.3.102
  • @swc/helpers 0.5.3
  • @swc/jest 0.2.29
  • @tailwindcss/forms 0.5.7
  • @testing-library/react 14.0.0
  • @types/adm-zip 0.5.5
  • @types/download 8.0.5
  • @types/eslint ~8.37.0
  • @types/express 4.17.21
  • @types/jest 29.5.12
  • @types/lodash.get 4.4.9
  • @types/node 18.19.26
  • @types/node-fetch 2.6.11
  • @types/react 18.2.62
  • @types/react-dom 18.2.19
  • @types/react-router-dom 5.3.3
  • @types/webpack-sources 3.2.3
  • @typescript-eslint/eslint-plugin 6.21.0
  • @typescript-eslint/parser 6.21.0
  • @vitest/coverage-istanbul 1.2.2
  • @vitest/coverage-v8 1.2.2
  • @vitest/ui 1.2.2
  • autoprefixer 10.4.17
  • babel-jest 29.7.0
  • babel-loader 9.1.3
  • classnames 2.5.0
  • command-join 3.0.0
  • comment-parser 1.4.1
  • commitizen ^4.3.0
  • concurrently 8.2.2
  • copy-webpack-plugin 11.0.0
  • cypress ^13.0.0
  • directory-tree 3.5.1
  • esbuild 0.20.2
  • eslint 8.56.0
  • eslint-config-next 13.5.6
  • eslint-config-prettier 9.1.0
  • eslint-plugin-cypress ^2.13.4
  • eslint-plugin-import 2.28.1
  • eslint-plugin-jsx-a11y 6.7.1
  • eslint-plugin-prettier 5.1.3
  • eslint-plugin-qwik 1.3.2
  • eslint-plugin-react 7.33.2
  • eslint-plugin-react-hooks 4.6.0
  • eslint-plugin-simple-import-sort 10.0.0
  • form-data 4.0.0
  • graceful-fs ^4.2.9
  • highlight.js 10.7.3
  • html-webpack-plugin 5.6.0
  • husky 8.0.3
  • inquirer 9.2.17
  • jest 29.7.0
  • jest-environment-jsdom 29.7.0
  • jest-environment-node 29.7.0
  • js-yaml 4.1.0
  • mammoth 1.6.0
  • merge-stream 2.0.0
  • mime-types 2.1.35
  • msw ^1.2.1
  • ngx-deploy-npm 7.1.0
  • node-fetch ~3.3.0
  • node-html-markdown 1.3.0
  • nodejieba 2.6.0
  • nx 17.2.8
  • nx-cloud 16.5.2
  • open ^10.0.0
  • openai 3.3.0
  • pdf-parse 1.1.1
  • postcss-calc 9.0.1
  • postcss-custom-properties 13.3.5
  • postcss-import 15.1.0
  • postcss-url 10.1.3
  • prettier 3.0.3
  • prettier-eslint 16.2.0
  • qwik-nx 1.1.1
  • qwik-speak 0.12.2
  • react-refresh 0.14.0
  • rimraf ^3.0.2
  • rollup-plugin-copy 3.5.0
  • stopword 2.0.8
  • strip-ansi ^6.0.0
  • swc-loader 0.2.3
  • tailwindcss 3.4.1
  • ts-jest 29.1.2
  • ts-node 10.9.1
  • tslib 2.6.2
  • tsup 7.2.0
  • typescript 5.3.3
  • url-loader 4.1.1
  • verdaccio 5.29.2
  • vinyl-fs 4.0.0
  • vite 5.0.10
  • vite-tsconfig-paths 4.2.3
  • vitest 1.2.2
  • vitest-fetch-mock ^0.2.2
  • vue-tsc 1.8.27
  • wast-loader ^1.11.5
  • webpack ^5.90.0
  • webpack-virtual-modules 0.6.1
  • whatwg-fetch ^3.6.2
  • node >=18
  • pnpm >=8.11.0
packages/core/package.json
  • webpack ^5.40.0
packages/enhanced-rspack/package.json
  • @rspack/core 0.5.0
packages/enhanced/package.json
  • upath 2.0.1
  • webpack ^5.0.0
packages/enhanced/test/configCases/container/1-container-full/node_modules/package.json
packages/enhanced/test/configCases/container/1-container-full/package.json
  • react *
  • node >=10.13.0
packages/enhanced/test/configCases/container/2-container-full/node_modules/package.json
packages/enhanced/test/configCases/container/2-container-full/package.json
  • react *
packages/enhanced/test/configCases/container/3-container-full/package.json
  • react *
packages/enhanced/test/configCases/container/exposed-overridables/node_modules/package.json
packages/enhanced/test/configCases/container/exposed-overridables/package.json
  • react 1.0.0
packages/enhanced/test/configCases/container/module-federation-with-shareScope/node_modules/package.json
packages/enhanced/test/configCases/container/module-federation-with-shareScope/package.json
  • react *
  • node >=10.13.0
packages/enhanced/test/configCases/container/multiple-runtime-chunk/node_modules/package.json
packages/enhanced/test/configCases/container/multiple-runtime-chunk/package.json
  • react *
  • node >=10.13.0
packages/enhanced/test/configCases/sharing/consume-module-ignore-warnings/package.json
  • package *
  • @scoped/package *
  • prefix *
packages/enhanced/test/configCases/sharing/consume-module/package.json
  • package *
  • @scoped/package *
  • prefix *
packages/enhanced/test/configCases/sharing/consume-multiple-versions-ignore-warnings/node_modules/my-module/package.json
packages/enhanced/test/configCases/sharing/consume-multiple-versions-ignore-warnings/node_modules/my-module2/package.json
packages/enhanced/test/configCases/sharing/consume-multiple-versions-ignore-warnings/node_modules/my-module3/package.json
packages/enhanced/test/configCases/sharing/consume-multiple-versions-ignore-warnings/node_modules/my-module4/package.json
  • shared *
packages/enhanced/test/configCases/sharing/consume-multiple-versions-ignore-warnings/package.json
  • shared2 >3.2.1
packages/enhanced/test/configCases/sharing/consume-multiple-versions/node_modules/my-module/package.json
packages/enhanced/test/configCases/sharing/consume-multiple-versions/node_modules/my-module2/package.json
packages/enhanced/test/configCases/sharing/consume-multiple-versions/node_modules/my-module3/package.json
packages/enhanced/test/configCases/sharing/consume-multiple-versions/node_modules/my-module4/package.json
  • shared *
packages/enhanced/test/configCases/sharing/consume-multiple-versions/package.json
  • shared2 >3.2.1
  • shared3 v1.0.0
  • shared5 v1.0.0
  • shared6 v1.0.0
  • shared19 ^1.0.0
packages/enhanced/test/configCases/sharing/consume-self-reference/node_modules/my-middleware/package.json
  • my-module *
packages/enhanced/test/configCases/sharing/consume-self-reference/node_modules/my-module/package.json
packages/enhanced/test/configCases/sharing/consume-self-reference/package.json
packages/enhanced/test/configCases/sharing/no-override-loaded/node_modules/package/package.json
packages/enhanced/test/configCases/sharing/no-override-loaded/package.json
  • package 1
packages/enhanced/test/configCases/sharing/provide-eager-module/node_modules/common/package.json
packages/enhanced/test/configCases/sharing/provide-eager-module/node_modules/uncommon/package.json
packages/enhanced/test/configCases/sharing/provide-eager-module/package.json
  • common *
packages/enhanced/test/configCases/sharing/provide-module/node_modules/package/package.json
packages/enhanced/test/configCases/sharing/provide-module/package.json
packages/enhanced/test/configCases/sharing/provide-multiple-versions/node_modules/my-module/node_modules/shared/package.json
packages/enhanced/test/configCases/sharing/provide-multiple-versions/node_modules/shared/package.json
packages/enhanced/test/configCases/sharing/provide-multiple-versions/node_modules/unused-module/node_modules/shared/package.json
packages/enhanced/test/configCases/sharing/provide-multiple-versions/package.json
packages/enhanced/test/configCases/sharing/provide-shared-with-runtime-chunk/node_modules/x/package.json
packages/enhanced/test/configCases/sharing/share-multiple-versions/node_modules/my-module/node_modules/shared/package.json
packages/enhanced/test/configCases/sharing/share-multiple-versions/node_modules/my-module/package.json
packages/enhanced/test/configCases/sharing/share-multiple-versions/node_modules/shared/package.json
packages/enhanced/test/configCases/sharing/share-multiple-versions/node_modules/unused-module/node_modules/shared/package.json
packages/enhanced/test/configCases/sharing/share-multiple-versions/package.json
packages/enhanced/test/configCases/sharing/share-plugin/node_modules/lib1/package.json
packages/enhanced/test/configCases/sharing/share-plugin/node_modules/lib3/package.json
packages/enhanced/test/configCases/sharing/share-plugin/node_modules/store/package.json
packages/enhanced/test/configCases/sharing/share-plugin/package.json
packages/managers/package.json
  • find-pkg 2.0.0
  • fs-extra 9.1.0
  • webpack 5.76.0
packages/manifest/package.json
  • find-pkg 2.0.0
  • chalk 3.0.0
packages/native-federation-tests/package.json
  • adm-zip ^0.5.10
  • ansi-colors ^4.1.3
  • axios ^1.6.7
  • rambda ^9.1.0
  • tsup ^7.0.0
  • unplugin ^1.9.0
packages/native-federation-typescript/package.json
  • adm-zip ^0.5.10
  • ansi-colors ^4.1.3
  • axios ^1.6.7
  • rambda ^9.1.0
  • unplugin ^1.9.0
  • typescript ^4.9.0 || ^5.0.0
  • vue-tsc ^1.0.24
packages/nextjs-mf/package.json
  • fast-glob ^3.2.11
  • webpack-sources ^3.2.3
  • eventemitter3 ^5.0.0
  • webpack ^5.40.0
  • next ^12 || ^13 || ^14
  • react ^17 || ^18
  • react-dom ^17 || ^18
  • styled-jsx *
packages/node/package.json
  • encoding ^0.1.13
  • node-fetch 2.7.0
  • next ^12||^13
  • react ^16||^17||^18
  • react-dom ^16||^17||^18
  • webpack ^5.40.0
packages/runtime-tools/package.json
packages/runtime/package.json
packages/sdk/package.json
packages/storybook-addon/package.json
  • @storybook/core-common 7.6.17
  • @storybook/node-logger 7.6.17
  • webpack 5.89.0
  • webpack-virtual-modules 0.6.1
  • @nx/react ^17.1.3
  • @nx/webpack ^17.1.3
  • @storybook/core-common ^6.5.16 || ^7.0.0
  • @storybook/node-logger ^6.5.16 || ^7.0.0
  • webpack ^5.75.0
  • webpack-virtual-modules ^0.5.0 || ^0.6.0
  • @module-federation/utilities ^3.0.6
  • @nx/react ~16.0.0 || ~17.0.0 || ~17.2.0
  • @nx/webpack ~16.0.0 || ~17.0.0 || ~17.2.0
packages/typescript/package.json
  • node-fetch 2.7.0
  • typescript *
  • vue-tsc ^1.0.24
  • webpack ^5.75.0
  • next *
  • react *
  • react-dom *
packages/utilities/package.json
  • react 18.2.0
  • webpack ^5.40.0
  • react-dom ^16 || ^17 || ^18
  • react ^16 || ^17 || ^18
packages/webpack-bundler-runtime/package.json
webpack/package.json
nvm
.nvmrc
  • node 18.19.1
apps/modernjs/.nvmrc

  • Check this box to trigger a request for Renovate to run again on this repository

Possible to keep node plugin Next.js agnostic?

I have module-federation/node, which is where this plugin comes from.

Is it possible to keep the plugin agnostic to allow us to import and install it from a registry instead of forking it into this codebase?

Move repo to NX based monorepo

the current setup is janky, but works
Ideally we take Valor's NX monorepo setup and lift this repo into that

We would need:

  • nextjs-mf to move into NX as a package
  • demo apps to consume nextjs-mf and build via nx
  • build and publish commands for releasing package to npm
  • preserve the nextjs-ssr package (since its fully TS) and take what we can from it, port nextjs-mf over to TS.
  • Once ported, kill nextjs-ssr and have nextjs-mf be the only package supporting MF on next universally

Error: Can't resolve 'react/jsx-runtime'

I tried to add module federation to a brand new nextjs app and i'm seeing this error. Full Error

mf-test (main)$ yarn build
yarn run v1.22.10
$ next build
info  - Using webpack 5. Reason: future.webpack5 option enabled https://nextjs.org/docs/messages/webpack5
info  - Checking validity of types  
info  - Creating an optimized production build  
Failed to compile.

ModuleNotFoundError: Module not found: Error: Can't resolve 'react/jsx-runtime' in '/Users/davidhu/Desktop/mf-test/src/pages'


> Build error occurred
Error: > Build failed because of webpack errors
    at /Users/davidhu/Desktop/mf-test/node_modules/next/dist/build/index.js:17:924
    at async Span.traceAsyncFn (/Users/davidhu/Desktop/mf-test/node_modules/next/dist/telemetry/trace/trace.js:6:584)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I checked node_modules and sees react/jsx-runtime.js in the directory. possibly related to this react issue. I can't seem to find regarding this fix.

Archive.zip

i zipped up a sample code that shows the issue. just run yarn build or yarn dev to see the error.

Here are the versions we are using

  "dependencies": {
    "@module-federation/nextjs-mf": "^0.2.1",
    "next": "10.2.2",
    "react": "17.0.2",
    "react-dom": "17.0.2"
  }

Any ideas?

Router === null on SSR

Just when I activate the module federation on the webpack config.

The value router from const router = useRouter(); in my _app.tsx comes up as null

Any idea what could be happening?

Thanks in advance!

Nextjs module federation doesn't work when import remote style-components

it work well when I access remote server 'component-kit'(localhost: 3000) , but It crashed when I access host server 'shell'(localhost: 3001).

image

it work well when I switch styled component to react component.

image


Remote Config

packages.json

image

next.config.js

image

components/title.tsx

image


Host Config

packages.json

image

next.config.js

image

_document.tsx

image

index.tsx

image

Dynamic import not working with SSR

The updated documentation shows how to dynamically import a federated module using next/dynamic:

const SampleComponent = dynamic(() => import("next2/sampleComponent"), {
  ssr: false,
});

While this works fine client-side, using ssr: true breaks the server-side rendering. Has anyone come across this issue following the updated documentation?

[SSR] Sharing Externals

Next.js in server builds make all node modules external modules to make the build smaller/faster

This presents a problem for module federation when sharing, if its external - its not added to share scope.

Theres a few options;

First we need to include any shared modules in webpack build for server.
In the past - ive done so like this

          // get share keys from user, filter out ones that need to be external
          const internalizableKeys = Object.keys(
            federationPluginOptions.shared
          ).filter((key) => {
            return key !== "react";
          });
          // take original externals regex
          const backupExternals = config.externals[0];
          // if externals is a function (like when you're not running in serverless mode or creating a single build)
          if (typeof backupExternals === "function") {
            // replace externals function with short-circuit, or fall back to original algo
            config.externals[0] = (mod, callback) => {
              if (!internalizableKeys.some((v) => mod.request.includes(v))) {
                return backupExternals(mod, callback);
              }
              return Promise.resolve();
            };
          }

However, next and react must remain external. This forced me to use a loader to patch share scope during runtime to include those keys

// language=JS
const shareNextInternals = `if (process.browser) {
  if(!__webpack_share_scopes__.default) {
     __webpack_init_sharing__('default');
  }
    window.__webpack_share_scopes__ = __webpack_share_scopes__
    if(!__webpack_share_scopes__.default.react) {
    Object.assign(__webpack_share_scopes__.default, {
      "react": {
        0: {
          loaded: true,
          get: () => Promise.resolve(() => require("react")),
        },
     },
    })
  }
  Object.assign(__webpack_share_scopes__.default, {
    "next/link": {
      [next.version]: {
        loaded: true,
        get: () => Promise.resolve(() => require("next/link")),
      },
    },
    "next/script": {
      [next.version]: {
        loaded: true,
        get: () => Promise.resolve(() => require("next/script")),
      },
    },
    "next/router": {
      [next.version]: {
        loaded: true,
        get: () => Promise.resolve(() => require("next/router")),
      },
    },
    "next/head": {
      [next.version]: {
        loaded: true,
        get: () => Promise.resolve(() => require("next/head")),
      },
    },
    "next/dynamic": {
      [next.version]: {
        loaded: true,
        get: () => Promise.resolve(() => require("next/dynamic")),
      },
    },
  });
} else {
  if(process.env.NEXT_PHASE !== 'phase-production-build') {
     __webpack_init_sharing__('default');
  }
  
  if(!__webpack_share_scopes__.default) {
      __webpack_share_scopes__.default = {}
  }
  global.__webpack_share_scopes__ = __webpack_share_scopes__
  const reactRequire = require("react");
  const nextLink = require("next/link");
  const nextScript = require("next/script");
  const nextRouter = require("next/router");
  const nextHead = require("next/head");
  const nextDynamic = require("next/dynamic");
  if(!__webpack_share_scopes__.default.react) {
    Object.assign(__webpack_share_scopes__.default, {
      "react": {
        0: {
          loaded: true,
          eager:true,
          get:()=> ()=> reactRequire,
        },
     },
    })
  }
  Object.assign(__webpack_share_scopes__.default, {
    "next/link": {
      0: {
        loaded: true,
        get: () => () => nextLink,
      },
    },
    "next/script": {
     0: {
        loaded: true,
        get: () => () => nextScript,
     },
    },
    "next/router": {
      0: {
        loaded: true,
        get: () => ()=> nextRouter,
      },
    },
    "next/head": {
      0: {
        loaded: true,
        get: () => ()=> nextHead,
      },
    },
    "next/dynamic": {
      0: {
        loaded: true,
        get: () => ()=> nextDynamic,
      },
    },
  })
  
  try {
    global.REMOTE_CONFIG = Object.assign(global.REMOTE_CONFIG || {},process.env.REMOTE_CONFIG)
  } catch(e) {
    // do nothing
  }
}
`;

module.exports = function (source) {
  const FederationPluginInstance = this._compiler.options.plugins.find(
    (plugin) => {
      if (
        plugin.constructor &&
        plugin.constructor.name === "ModuleFederationPlugin"
      ) {
        return true;
      }
    }
  );
  let manualInitializationString = [];
  if (FederationPluginInstance && FederationPluginInstance._options.remotes) {
    manualInitializationString.push("if (process.browser) {");
    Object.keys(FederationPluginInstance._options.remotes).forEach((remote) => {
      manualInitializationString.push(
        `window.${remote}?.init(__webpack_share_scopes__.default);`
      );
    });
    manualInitializationString.push("};");
  }
  manualInitializationString = manualInitializationString.join("\n");
  return shareNextInternals + manualInitializationString + source;
};

Im open to suggestions on how to solve or improve sharing of next internals when on server build.

One idea i had was to create a new runtimeRequirement, adding another webpack closure and function to the webpack runtime which assigns react,react-dom, and next internal packages to the object during startup.

The other possible option is to exclude these from share scope on the server which should make the remoteEntry use require(react) natively.
This would only be used for the react and next libraries themselves - everything else needs to be bundled as we cannot guarentee these packages will exist in the hosts node_modules

Issues hosting app1 on vercel

I'm trying to test this concept out on vercel and am running into a series of errors. Here are the logs, just trying to host the source code from this repo for app1.

The error I get is Module not found: Error: Can't resolve 'encoding'

image

And here's the full log output.
`

18:50:23 Cloning github.com/Speedway-Motors/next-mf-blogpost (Branch: main, Commit: 383ef9d)
18:50:24 Cloning completed in 869ms
18:50:24 Analyzing source code...
18:50:25 Installing build runtime...
18:50:25 Build runtime installed: 461.359ms
18:50:26 Looking up build cache...
18:50:26 Build cache not found
18:50:26 Installing dependencies...
18:50:26 yarn install v1.22.4
18:50:26 [1/4] Resolving packages...
18:50:27 warning Resolution field "[email protected]" is incompatible with requested version "[email protected]"
18:50:27 [2/4] Fetching packages...
18:50:32 info [email protected]: The platform "linux" is incompatible with this module.
18:50:32 info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
18:50:32 [3/4] Linking dependencies...
18:50:35 [4/4] Building fresh packages...
18:50:36 Done in 9.60s.
18:50:36 Running "yarn run build"
18:50:36 yarn run v1.22.4
18:50:36 $ next build
18:50:37 info - Creating an optimized production build...
18:50:37 Attention: Next.js now collects completely anonymous telemetry regarding usage.
18:50:37 This information is used to shape Next.js' roadmap and prioritize features.
18:50:37 You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
18:50:37 https://nextjs.org/telemetry
18:50:45 [webpack.cache.PackFileCacheStrategy] Serializing big strings (121kiB) impacts deserialization performance (consider using Buffer instead and decode when needed)
18:50:47 Failed to compile.
18:50:47 ModuleNotFoundError: Module not found: Error: Can't resolve 'encoding' in '/vercel/workpath0/app1/node_modules/next/node_modules/node-fetch/lib'
18:50:47 > Build error occurred
18:50:47 Error: > Build failed because of webpack errors
18:50:47 at build (/vercel/workpath0/app1/node_modules/next/dist/build/index.js:15:918)
18:50:47 error Command failed with exit code 1.
18:50:47 info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
18:50:47 Error: Command "yarn run build" exited with 1
18:50:49 Done with "package.json"

`

Render 404 page

Found a TODO comment on line 59 of file demo/shared/index.js

Plugin is not compatible with next ^10.0.5

After upgrading to [email protected] I'm getting following error:

node_modules/webpack-sources/lib/ConcatSource.js:42
			source += typeof child === "string" ? child : child.source();
			                                                    ^
TypeError: Cannot read property 'source' of undefined

Example reproduction: https://github.com/adam187/next-mf-example/tree/next-10-0-5

After upgrading to [email protected]

Error: Cannot find module 'webpack-sources/lib/ConcatSource'

On a side note, looks like this version change how you choose webpack version from resolutions to config option:

// next.config.js
  ...
  future: {
    webpack5: true,
  },

and now next is bundled with both versions (4 and 5) vercel/next.js#21679

Example reproduction: https://github.com/adam187/next-mf-example/tree/next-10-0-6

NextJS Plugin not working with Webpack v5.22.0 and up

I'm not sure if it's best to file this here, in the example repo, or in the webpack repo, let me know if there's a better place for this.

I've been unable to get module federation working with the latest version of NextJS, which is using wepback 5.24.4. The explanation below uses the nextjs example at https://github.com/module-federation/module-federation-examples/tree/master/nextjs.

When running the example in the nextjs folder, I get ReferenceError: next1 is not defined. It seems that next1 is not set as a global variable in the browser.

Screen Shot 2021-03-15 at 4 06 14 PM

Though the package.json has resolutions to set the Webpack version to 5.18.0, when the webpack5 flag in nextjs is set, it ignores the resolution version and instead pulls in version 5.24.4 (you can see this by adding console.log(options.webpack.version) to the webpack function in next.config.js.

I did some testing with different version of Webpack 5 (using resolutions and an older version of nextjs before they added the webpack5 flag, you can test this in the example repo by removing the caret in front of the dependency next: "^10.0.0"), and determined that the last working version without this error was 5.21.2. Looking at the remoteEntry files that are emitted using v5.21.2 vs v5.22.0, I see that the global variable assignment is missing from the generated remoteEntry file after v5.22.0.

Working - Webpack v5.21.2:
Screen Shot 2021-03-15 at 5 14 05 PM

Not working - Webpack v5.22.0
Screen Shot 2021-03-15 at 5 15 12 PM

That's as far as I've been able to trace things, I looked through Webpack's 5.22.0 release but didn't see anything obvious. I've also not been able to find a way to actually override the version of webpack 5 in the most recent version of nextjs. I'd really like to adopt module federation in our nextjs apps. Let me know if there's any more info you need. Thanks!

SWC Minify mangles lib name

Until we have the capability of using an .swcrc file with Next, this is just something to be aware of.
When using a configuration object like so:

/**
 * Advanced configuration for Next.js
 * @type { import('next').NextConfig }
 */
const nextConfig = {
    experimental: {
        browsersListForSwc: true,
        legacyBrowsers: false
    },
    swcMinify: true,
    webpack(config, options) {
        // ...NextFederationPlugin({ name: next1, ... })
        return config;
    }
}

swcMinify will compress and mangle your remote entry which will rename var next1 = ... to something like var a = ... when running a production build.

need to handle all other cases like when remote is not a @ syntax string

Found a TODO comment on line 221 of file node-plugin/streaming/LoadFileChunkLoadingRuntimeModule.js

Remotes could also be promise new promise functions. If thats the case - there needs to be either an abstraction around when a user uses a promise function or rules where they must resolve a string with the @ syntax back to use so we can parse and load the remote like normal

command not found: nextjs-mf

Steps to reproduce:

  1. yarn global add @module-federation/nextjs-mf
  2. nextjs-mf upgrade -p 3001 (in a fresh Next.js installation)

Expected output

nextjs-mf upgrade runs through the Next.js folder.

Actual output

command not found: nextjs-mf

Tried uninstalling, re-installing, using npm install instead of yarn etc - nothing helps.
Not sure if it matters, but when installing it globally I get the following warning:

warning "@module-federation/[email protected]" has no binaries

Node version: v15.5.1

Remotes css breaks

When running remote independently the page looks fine, but when importing the remote inside all of the css breaks but app is running. Remotes use css modules and styled-components

"next": "10.2.3",
tried on "@module-federation/nextjs-mf": "0.0.2"
tried on "@module-federation/nextjs-mf": "2.3.1"

Improve documentation

Readme was geared for a private repo. Contribution guidelines, and additional docs are required

Integrate chunk manifest from react loadable

This works in ssr plugin, but needs to be re-implemented here.

I need to ship the loadable manifest as part of the remote entry and reattach it to next.js

Was previously done like this, which was dirty but worked.

const React = require("react");
const { Head } = require("next/document");
const path = require("path");
const crypto = require("crypto");
const generateDynamicRemoteScript = (remoteContainer) => {
  const [name, path] = remoteContainer.path.split("@");
  const remoteUrl = new URL(path);
  remoteUrl.pathname = remoteUrl.pathname.replace("ssr", "chunks");
  remoteUrl.searchParams.set("cbust", Date.now());
  return {
    [name]: React.createElement("script", {
      "data-webpack": name,
      src: remoteUrl.toString(),
      async: true,
      key: name,
    }),
  };
};

const extractChunkCorrelation = (remoteContainer, lookup, request) => {
  if (
    remoteContainer &&
    remoteContainer.chunkMap &&
    remoteContainer.chunkMap.federatedModules
  ) {
    const path = remoteContainer.path.split("@")[1];
    const [baseurl] = path.split("static/ssr");
    remoteContainer.chunkMap.federatedModules.map((federatedRemote) => {
      federatedRemote.exposes[request].forEach((remoteChunks) => {
        remoteChunks.chunks.map((chunk) => {
          if (!lookup.files.includes(new URL(chunk, baseurl).href)) {
            lookup.files.push(new URL(chunk, baseurl).href);
          }
        });
      });
    });
  } else {
    console.warn(
      "Module Federation:",
      "no federated modules in chunk map OR experiments.flushChunks is disabled"
    );
  }
};

const extractLocalRemoteImport = (remoteContainer, lookup, request) => {
  if (
    remoteContainer &&
    remoteContainer.chunkMap &&
    remoteContainer.chunkMap.loadable &&
    remoteContainer.chunkMap.loadable[request]
  ) {
    const path = remoteContainer.path.split("@")[1];
    const [baseurl] = path.split("static/ssr");
    remoteContainer.chunkMap.loadable[request].files.map((chunk) => {
      if (!lookup.files.includes(new URL(chunk, baseurl).href)) {
        lookup.files.push(new URL(chunk, baseurl).href);
      }
    });
  } else {
    console.warn(
      "Module Federation:",
      "unable to understand local remote import OR experiments.flushChunks is disabled"
    );
  }
};
const requireMethod =
  typeof __non_webpack_require__ !== "undefined"
    ? __non_webpack_require__
    : require;

let foundNextFolder = null;
if (!foundNextFolder) {
  foundNextFolder = Object.keys(requireMethod.cache).find((key) => {
    if (key.includes(".next")) {
      return true;
    }
  });
}
const manifestPath = path.join(
  foundNextFolder.split(".next")[0],
  ".next/react-loadable-manifest.json"
);
let remotes = {};
const loadableManifest = requireMethod(manifestPath);
requireMethod.cache[manifestPath].exports = new Proxy(loadableManifest, {
  get(target, prop, receiver) {
    if (!target[prop]) {
      let remoteImport = prop.split("->")[1];

      if (remoteImport) {
        let isLocalImportLike = false;
        remoteImport = remoteImport.trim();
        const [remote, module] = remoteImport.split("/");
        if (!global.loadedRemotes[remote]) {
          isLocalImportLike = true;
          console.log("needs to search for a local import", prop);
        }
        if (!remotes[remote] && global.loadedRemotes[remote]) {
          Object.assign(
            remotes,
            generateDynamicRemoteScript(global.loadedRemotes[remote])
          );
        }

        const dynamicLoadableManifestItem = {
          id: prop,
          files: [],
        };
        // TODO: figure out who is requesting module
        let remoteModuleContainerId;
        Object.values(global.loadedRemotes).find((remote) => {
          if (
            remote.chunkMap &&
            remote.chunkMap.federatedModules[0] &&
            remote.chunkMap.federatedModules[0].remoteModules
          ) {
            if (
              remote.chunkMap.federatedModules[0].remoteModules[remoteImport]
            ) {
              remoteModuleContainerId =
                remote.chunkMap.federatedModules[0].remoteModules[remoteImport];
              return true;
            }
          }
          if (
            remote.chunkMap &&
            remote.chunkMap.loadable &&
            remote.chunkMap.loadable[prop]
          ) {
            console.log("extracting local import from this loadable map", prop);
            extractLocalRemoteImport(remote, dynamicLoadableManifestItem, prop);
            return true;
          }
        });

        if (!isLocalImportLike) {
          if (
            remoteModuleContainerId &&
            process.env.NODE_ENV !== "development"
          ) {
            dynamicLoadableManifestItem.id = remoteModuleContainerId;
          }
          extractChunkCorrelation(
            global.loadedRemotes[remote],
            dynamicLoadableManifestItem,
            `./${module}`
          );
        }
        return dynamicLoadableManifestItem;
      }
    }
    return target[prop];
  },
});
const flushChunks = async (remoteEnvVar = process.env.REMOTES) => {
  remotes = {};
  const remoteKeys = Object.keys(remoteEnvVar);
  const preload = [];

  try {
    for (const key in loadableManifest) {
      const [where, what] = key.split("->");
      const request = what.trim();
      const foundFederatedImport = remoteKeys.find((remoteKey) => {
        return request.startsWith(`${remoteKey}/`);
      });
      if (foundFederatedImport) {
        const remotePreload = remoteEnvVar[foundFederatedImport]().then(
          (remoteContainer) => {
            Object.assign(
              remotes,
              generateDynamicRemoteScript(remoteContainer)
            );

            const inferRequest = what.split(`${foundFederatedImport}/`)[1];
            const request = `./${inferRequest}`;
            extractChunkCorrelation(
              remoteContainer,
              loadableManifest[key],
              request
            );
          }
        ).catch((err) => {
          console.error("Error loading remote", err);
          return Promise.resolve();
        });
        preload.push(remotePreload);
      }
    }
    await Promise.all(preload);
    return remotes;
  } catch (e) {
    console.error("Module Federation: Could not flush chunks", e);
  }
  return [];
};

export class ExtendedHead extends Head {
  constructor(props, context) {
    super(props, context);
    this.context = context;
  }
  getCssLinks(files) {
    const cssLinks = super.getCssLinks(files);
    if (Array.isArray(cssLinks)) {
      return cssLinks.map((chunk) => {
        if (!chunk) return null;
        const [prefix, asset] = chunk.props.href.split(
          this.context.assetPrefix
        );
        if (
          chunk.props.href &&
          chunk.props.href.startsWith("/") &&
          chunk.props.href.includes("http")
        ) {
          return React.cloneElement(chunk, {
            ...chunk.props,
            href: `http${chunk.props.href.split("http")[1]}`,
          });
        } else if (
          chunk.props.href &&
          chunk.props.href.includes("-fed.") &&
          this.context.assetPrefix
        ) {
          const replacedArg = this.context.assetPrefix.endsWith("/")
            ? chunk.props.href.replace(`${this.context.assetPrefix}_next/`, "")
            : chunk.props.href.replace(
                `${this.context.assetPrefix}/_next/`,
                ""
              );
          return React.cloneElement(chunk, {
            ...chunk.props,
            href: replacedArg,
          });
        } else if (asset.includes("http") && asset.startsWith("/")) {
          return React.cloneElement(chunk, {
            ...chunk.props,
            href: `http${asset.split("http")[1]}`,
          });
        } else return chunk;
      });
    }
    return cssLinks;
  }
  getDynamicChunks(files) {
    const dynamicChunks = super.getDynamicChunks(files);
    return dynamicChunks.map((chunk) => {
      if (!chunk) return null;
      if (chunk.props.src.startsWith("/") && chunk.props.src.includes("http")) {
        return React.cloneElement(chunk, {
          ...chunk.props,
          src: `http${chunk.props.src.split("http")[1]}`,
        });
      } else if (
        chunk.props.src.includes("-fed.") &&
        this.context.assetPrefix
      ) {
        const replacedArg = this.context.assetPrefix.endsWith("/")
          ? chunk.props.src.replace(`${this.context.assetPrefix}_next/`, "")
          : chunk.props.src.replace(`${this.context.assetPrefix}/_next/`, "");
        return React.cloneElement(chunk, {
          ...chunk.props,
          src: replacedArg,
        });
      }
      return chunk;
    });
  }
}

[SSR] Adjust Externals algorithm to bundle shared modules

Right now all node modules are externalized in the child compiler (ssr), this means they cannot be streamed via federation.

Shared modules that are not next/,react-dom,react, or styled-jsx should be "internalized" into both host/remote

          // get share keys from user, filter out ones that need to be external
          const internalizableKeys = Object.keys(
            federationPluginOptions.shared
          ).filter((key) => {
            return // if not a key from DEFAULT_SHARE_SCOPE
          });
          // take original externals regex
          const backupExternals = config.externals[0];
          // if externals is a function (like when you're not running in serverless mode or creating a single build)
          if (typeof backupExternals === "function") {
            // replace externals function with short-circuit, or fall back to original algo
            config.externals[0] = (mod, callback) => {
              if (!internalizableKeys.some((v) => mod.request.includes(v))) {
                return backupExternals(mod, callback);
              }
              return Promise.resolve();
            };
          }

Following the README MF doesn't work

Reproduction

Due to the way CSB works, please visit both and wait for them to start before inspecting the results

Steps

  1. Follow steps in README
  2. Observe result

Expected

Federated remote loads in host container.

Experienced

Federated remote entry loads in host container, however the modules are pulled in from relative path of the host as opposed to the remote. Because of this they 404 and MF fails to initialise.

Environment

Additional Information

The host seems to be working correctly when trying with remote sources created in another way, e.g.: this one: https://kevinmfe.s3.amazonaws.com/app2/dist/remoteEntry.js, which comes from the following article: https://thekevinwang.com/2021/03/26/micro-frontends-nextjs/.

What would be the script URL to load the static chunk js when local/development environment?

import Document, { Html, Head, Main, NextScript } from "next/document";

class MyDocument extends Document {
  static async getInitialProps(ctx) {
    const initialProps = await Document.getInitialProps(ctx);
    return { ...initialProps };
  }

  render() {
    return (
      <Html>
        <Head />
        <body>
          <Main />
          <script src="http://next2-domain-here.com/_next/static/chunks/remoteEntry.js" />
          <NextScript />
        </body>
      </Html>
    );
  }
}

export default MyDocument;

Error: Cannot find module 'commander' on nextjs-mf upgrade -p 3001

team, commander is missing when tried to auto upgrade the newly created nextjs app

nextjs-mf upgrade -p 3001
internal/modules/cjs/loader.js:968
  throw err;
  ^

Error: Cannot find module 'commander'
Require stack:
- /Users/userName/.config/yarn/global/node_modules/@module-federation/nextjs-mf/bin/nextjs-mf.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
    at Function.Module._load (internal/modules/cjs/loader.js:841:27)
    at Module.require (internal/modules/cjs/loader.js:1025:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/Users/userName/.config/yarn/global/node_modules/@module-federation/nextjs-mf/bin/nextjs-mf.js:2:21)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/userName/.config/yarn/global/node_modules/@module-federation/nextjs-mf/bin/nextjs-mf.js'
  ]
}

Vendor bundles requested from incorrect host:port when using Next 11

Please see the example repo https://github.com/Pkearney2021/module-federation-next11

Expected behaviour: Bundles from the remote a requested from the correct host and port

Actual behaviour: The bundles are being requested from the current host.\

http://localhost:3001/_next/static/chunks/vendors-node_modules_react_jsx-dev-runtime_js.js
Should be
http://localhost:3000/_next/static/chunks/vendors-node_modules_react_jsx-dev-runtime_js.js

shared strictVersion uses this module version instead of the package version

      shared: {
        react: {
          eager: true,
          singleton: true,
          strictVersion: true,
          requiredVersion: deps.react,
        },

adding the strictVersion key causes this error

Uncaught Error: Unsatisfied version 1.1.2 of shared singleton module react (required =17.0.2)

Looks like it's somehow using the version of this package instead of the specific package.

seems like this packge is just passing the shared key into the ModuleFederationPlugin

https://github.com/module-federation/nextjs-mf/blob/main/withModuleFederation.js#L70

Next.js - getting "ReferenceError: __webpack_modules__ is not defined"

I have "app1" that exports a few components. Then the "app2" consumes those components.

When the "app2" loads everything works fine however when I navigate to another page ( and if this page uses certain components that "app1" exposes ) I get "ReferenceError: webpack_modules is not defined". If I refresh the page everything seems to be working and this error is gone.

Anyone else has this issue?

I am using:
"next": "10.0.2",
"@module-federation/nextjs-mf": "^0.0.2",
"react": "17.0.1",
"react-dom": "17.0.1",

"resolutions": {
"webpack": "5.18.0"
},

Use react- Redux to report an error!

When I use the connect of react-redux

Error: Could not find "store" in the context of "Connect(IndexPage)". Either wrap the root component in a <Provider>, or pass a custom React context provider to <Provider> and the corresponding React context consumer to Connect(IndexPage) in connect options.

Refer to the issue:
reduxjs/react-redux#1569

Cannot find module, when running in Windows enviroment

A project that is a exact clone from Jack Harrington's nextjs-mf.
Nothing has changed. But when I try to run in Windows (only), I got this error:
error

But when running in linux, everything goes well.

The path in next.config.js

        // For SSR, resolve to disk path (or you can use code streaming if you have access)
        home: isServer
          ? path.resolve(
              __dirname,
              "../home/.next/server/static/runtime/remoteEntry.js"
            )
          : "home", // for client, treat it as a global
      }```

Remove moveFilesToClientDirectory

This can be killed off thanks to additonalAssets pipeline.

There is still a hacky directory crawl/listing on CSR build to find the ssr folder and side-load it into the main compilation asset.
That will be a separate issue to try and improve though

Using a name withe kebab case breaks server and MergeRuntime.

Followed through @jherr 's video

Called my consumer nextjs app next-app-2.

After following instructions and running the consumer app I got a blank screen.

fiddled around with _document.js and next.config.js - commenting out stuff here and there which got it working.

re-added execution of MergeRuntime in config file and recreated blank screen.

Opened source files and main.js... next.js static chunk and saw that the eval got broken by the next-app-2 name:

image

Changing the name in the config file to a camelCase fixed the issue.

Could be good to add protection from this, or add documentation not to use that sort of app name (at least in the next.config.js)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.