Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@module-federation/[email protected] module not found error #1961

Closed
5 tasks done
Capricair opened this issue Jan 15, 2024 · 34 comments
Closed
5 tasks done

@module-federation/[email protected] module not found error #1961

Capricair opened this issue Jan 15, 2024 · 34 comments
Assignees
Labels
nextjs-mf nextjs-mf package identifier

Comments

@Capricair
Copy link

Capricair commented Jan 15, 2024

Describe the bug

@module-federation/[email protected] throw module not found error when start dev server, but the same code works fine in codesandbox, reinstall it didn't work either, but version 8.1.3 works fine.

dependencies:

next: 12.3.1
react: 17.0.2
react-dom: 17.0.2
PS E:\work\app-store> npm run dev

> [email protected] dev
> cross-env NODE_ENV=development next dev -p 3001

ready - started server on 0.0.0.0:3001, url: http://localhost:3001
info  - Loaded env from E:\work\app-store\.env
NEXT_PUBLIC_BASE_PATH: undefined
Error: Cannot find module 'E:\work\app-store\node_modules\next\dist\compiled\lib\util\makeSerializable'
Require stack:
- E:\work\app-store\node_modules\@module-federation\enhanced\dist\src\lib\container\ContainerExposedDependency.js
- E:\work\app-store\node_modules\@module-federation\enhanced\dist\src\lib\container\ContainerEntryModule.js
- E:\work\app-store\node_modules\@module-federation\enhanced\dist\src\lib\container\HoistContainerReferencesPlugin.js
- E:\work\app-store\node_modules\@module-federation\enhanced\dist\src\wrapper\HoistContainerReferencesPlugin.js
- E:\work\app-store\node_modules\@module-federation\enhanced\dist\src\index.js
- E:\work\app-store\node_modules\@module-federation\nextjs-mf\dist\src\internal.js
- E:\work\app-store\node_modules\@module-federation\nextjs-mf\dist\src\plugins\NextFederationPlugin\next-fragments.js
- E:\work\app-store\node_modules\@module-federation\nextjs-mf\dist\src\plugins\NextFederationPlugin\index.js
- E:\work\app-store\node_modules\@module-federation\nextjs-mf\dist\src\index.js
- E:\work\app-store\next.config.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
    at mod._resolveFilename (E:\work\app-store\node_modules\next\dist\build\webpack\require-hook.js:27:32)
    at mod._resolveFilename (E:\work\app-store\node_modules\next\dist\build\webpack\require-hook.js:27:32)
    at mod._resolveFilename (E:\work\app-store\node_modules\next\dist\build\webpack\require-hook.js:27:32)
    at Module._load (node:internal/modules/cjs/loader:922:27)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:119:18)
    at Object.<anonymous> (E:\work\app-store\node_modules\@module-federation\enhanced\dist\src\lib\container\ContainerExposedDependency.js:8:26)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'E:\\work\\app-store\\node_modules\\@module-federation\\enhanced\\dist\\src\\lib\\container\\ContainerExposedDependency.js',
    'E:\\work\\app-store\\node_modules\\@module-federation\\enhanced\\dist\\src\\lib\\container\\ContainerEntryModule.js',
    'E:\\work\\app-store\\node_modules\\@module-federation\\enhanced\\dist\\src\\lib\\container\\HoistContainerReferencesPlugin.js',
    'E:\\work\\app-store\\node_modules\\@module-federation\\enhanced\\dist\\src\\wrapper\\HoistContainerReferencesPlugin.js',
    'E:\\work\\app-store\\node_modules\\@module-federation\\enhanced\\dist\\src\\index.js',
    'E:\\work\\app-store\\node_modules\\@module-federation\\nextjs-mf\\dist\\src\\internal.js',
    'E:\\work\\app-store\\node_modules\\@module-federation\\nextjs-mf\\dist\\src\\plugins\\NextFederationPlugin\\next-fragments.js',
    'E:\\work\\app-store\\node_modules\\@module-federation\\nextjs-mf\\dist\\src\\plugins\\NextFederationPlugin\\index.js',
    'E:\\work\\app-store\\node_modules\\@module-federation\\nextjs-mf\\dist\\src\\index.js',
    'E:\\work\\app-store\\next.config.js'
  ]
}

Reproduction

https://codesandbox.io/p/devbox/module-federation-x4qjrt?layout=%257B%2522sidebarPanel%2522%253A%2522EXPLORER%2522%252C%2522rootPanelGroup%2522%253A%257B%2522direction%2522%253A%2522horizontal%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522id%2522%253A%2522ROOT_LAYOUT%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522clreaqnam0007356hcnits3rr%2522%252C%2522sizes%2522%253A%255B70%252C30%255D%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522EDITOR%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522id%2522%253A%2522clreaqnal0002356hg57oqztm%2522%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522SHELLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522id%2522%253A%2522clreaqnal0004356hry63c7rh%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522DEVTOOLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522id%2522%253A%2522clreaqnal0006356htc9yst8k%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%252C%2522sizes%2522%253A%255B50%252C50%255D%257D%252C%2522tabbedPanels%2522%253A%257B%2522clreaqnal0002356hg57oqztm%2522%253A%257B%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clreaqnak0001356h0upnwz9u%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522FILE%2522%252C%2522filepath%2522%253A%2522%252FREADME.md%2522%257D%255D%252C%2522id%2522%253A%2522clreaqnal0002356hg57oqztm%2522%252C%2522activeTabId%2522%253A%2522clreaqnak0001356h0upnwz9u%2522%257D%252C%2522clreaqnal0006356htc9yst8k%2522%253A%257B%2522id%2522%253A%2522clreaqnal0006356htc9yst8k%2522%252C%2522activeTabId%2522%253A%2522clrebaq6202p9356hd8rea85b%2522%252C%2522tabs%2522%253A%255B%257B%2522type%2522%253A%2522UNASSIGNED_PORT%2522%252C%2522port%2522%253A3000%252C%2522id%2522%253A%2522clrebaq6202p9356hd8rea85b%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522path%2522%253A%2522%252F%2522%257D%255D%257D%252C%2522clreaqnal0004356hry63c7rh%2522%253A%257B%2522id%2522%253A%2522clreaqnal0004356hry63c7rh%2522%252C%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clreb65fh02d7356hxtqmjowg%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TERMINAL%2522%252C%2522shellId%2522%253A%2522clreb66p200bxefgeerx9e7cs%2522%257D%255D%252C%2522activeTabId%2522%253A%2522clreb65fh02d7356hxtqmjowg%2522%257D%257D%252C%2522showDevtools%2522%253Atrue%252C%2522showShells%2522%253Atrue%252C%2522showSidebar%2522%253Atrue%252C%2522sidebarPanelSize%2522%253A15%257D

Used Package Manager

npm

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (8) x64 Intel(R) Core(TM) i3-10100 CPU @ 3.60GHz
    Memory: 5.66 GB / 15.67 GB
  Binaries:
    Node: 18.18.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.21 - C:\Program Files\nodejs\yarn.CMD
    npm: 9.8.1 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (120.0.2210.133)
    Internet Explorer: 11.0.19041.3636

Validations

@gryp17
Copy link

gryp17 commented Jan 15, 2024

Same issue here. Only managed to get it working using next 13.4.4 and @module-federation/nextjs-mf 6.0.4. Upgrading nextjs-mf to version 8+ causes the same module not found error. Even this demo throws the same error message.

@yunusileri
Copy link

I have that same problem. Version 8.1.3 works in dev mode, it does not work after build. When I upgrade to a higher version, I get a Module not found error. The only version I can run right now is 5.12.11.

@richardklotz
Copy link

I found that there are two (at least) issues on windows. One is with how the webpack path is calculated and the other is the entry file located at node_modules\.federation. Fixing both of those allows the app to start.

Running on Windows

normalizeWebpackPath:

=========webpackErrLocation=============== at webpack (C:\code\TestApp\node_modules\webpack\lib\webpack.js:167:32)
=========webpackLocationWithDetail======== C:\code\TestApp\node_modules\webpack\lib\webpack.js:167:32
=========webpackPath====================== C

node_modules\.federation
\ needs escaped

import federation from 'C:\code\TestApp\node_modules\@module-federation\webpack-bundler-runtime\dist\index.cjs.js';
import plugin_0 from 'C:\code\TestApp\node_modules\@module-federation\nextjs-mf\dist\src\plugins\container\runtimePlugin.js';

__webpack_require__.federation = { ...federation, ...__webpack_require__.federation };
if (!__webpack_require__.federation.instance) {
	__webpack_require__.federation.initOptions.plugins = ([
		plugin_0(),
	])
	__webpack_require__.federation.instance = __webpack_require__.federation.runtime.init(__webpack_require__.federation.initOptions);
	if (__webpack_require__.federation.attachShareScopeMap) {
		__webpack_require__.federation.attachShareScopeMap(__webpack_require__)
	}
	if (__webpack_require__.federation.installInitialConsumes) {
		__webpack_require__.federation.installInitialConsumes()
	}
}

Running on Windows WSL

normalizeWebpackPath:

=========webpackErrLocation===============  at webpack (/root/code/TestApp/node_modules/webpack/lib/webpack.js:167:32)
=========webpackLocationWithDetail======== /root/code/TestApp/node_modules/webpack/lib/webpack.js:167:32
=========webpackPath====================== /root/code/TestApp/node_modules/webpack/lib/webpack.js`

node_modules\.federation

import federation from '/root/code/TestApp/node_modules/@module-federation/nextjs-mf/node_modules/@module-federation/webpack-bundler-runtime/dist/index.cjs.js';
import plugin_0 from '/root/code/TestApp/node_modules/@module-federation/nextjs-mf/dist/src/plugins/container/runtimePlugin.js';

__webpack_require__.federation = {...federation,...__webpack_require__.federation};
if(!__webpack_require__.federation.instance){
	__webpack_require__.federation.initOptions.plugins = ([
		plugin_0(),
	])
	__webpack_require__.federation.instance = __webpack_require__.federation.runtime.init(__webpack_require__.federation.initOptions);
	if(__webpack_require__.federation.attachShareScopeMap){
		__webpack_require__.federation.attachShareScopeMap(__webpack_require__)
	}
	if(__webpack_require__.federation.installInitialConsumes){
		__webpack_require__.federation.installInitialConsumes()
	}
}

@ScriptedAlchemy
Copy link
Member

Looks like this is windows related.
#1997

@senuravihanjayadeva
Copy link

Same issue here

@armedi
Copy link

armedi commented Jan 26, 2024

Same issue here.
We are trying to migrate our CRA based apps to Next.js. Majority of team members are using windows

@zhoushaw zhoushaw added the nextjs-mf nextjs-mf package identifier label Jan 30, 2024
@Icammarano
Copy link

I have same issue in linux, Nextjs 14.0.1, module-federation 8.1.10 and webpack 5.90.1. Need the solution for this error

@fgh151
Copy link

fgh151 commented Feb 7, 2024

I have same issue in linux, Nextjs 14.1.0, module-federation 8.1.10 and webpack 5.90.1. Need the solution for this error

@renan-britz-mgm
Copy link

renan-britz-mgm commented Feb 11, 2024

Hey everyone, remember to edit your package.json scripts like below, otherwise you'll get the Cannot find module [...]makeSerializable error:

"scripts": {
  "dev": "rimraf .next && NEXT_PRIVATE_LOCAL_WEBPACK=true next dev",
  "build": "NEXT_PRIVATE_LOCAL_WEBPACK=true next build"
  // ...
}

NEXT_PRIVATE_LOCAL_WEBPACK=true is required.

@carlosfvp
Copy link

Hey everyone, remember to edit your package.json scripts like below, otherwise you'll get the Cannot find module [...]makeSerializable error:

"scripts": {
  "dev": "rimraf .next && NEXT_PRIVATE_LOCAL_WEBPACK=true next dev",
  "build": "NEXT_PRIVATE_LOCAL_WEBPACK=true next build"
  // ...
}

NEXT_PRIVATE_LOCAL_WEBPACK=true is required.

this doesn't fix the makeSerializable error

@mtls-david-devargas
Copy link

same issue here

@jynzo94
Copy link

jynzo94 commented Feb 15, 2024

I receive this error too.
I have to start new project with nextjs and module federation. Any ideas how to proceed?

@ScriptedAlchemy
Copy link
Member

try latest version. If windows user use WSL. you can try .env as well and set it in there

@newmercer
Copy link

@ScriptedAlchemy I'm on 5.12.7 and wanted to upgrade it to 8.2.2.
Getting below error with Module Not Found
image
I have next 13, react 18 installed.

@semonec
Copy link

semonec commented Mar 13, 2024

@ScriptedAlchemy Same error

nextjs: 14.1.0
@module-federation/nextjs-mf: 8.2.2
macOS: 13.6.4
node: v20.9.0 (same as v18, v20.10.0)

script from package.json

    "dev": "rm -rf .next && NEXT_PRIVATE_LOCAL_WEBPACK=true next dev",

next.config.mjs

const moduleFederationConfig = {
  name: 'commonHost',
  remotes: {
    homepage: "homepage@http://localhost:3001/remoteEntry.js"
  },
  filename: 'static/chunks/remoteEntry.js',
  exposes: {},
  shared: {},
  extraOptions: {},
}

const nextConfig = {
  env,
  reactStrictMode: false,
  images: {
    unoptimized: true, // Disables the default behavior of Next.js to automatically optimize images for SSG
  },
  // output: 'export',
  webpack(config, options) {
    if (!options.isServer) {
      config.plugins.push(new NextFederationPlugin(moduleFederationConfig))
    }
    return config
  },
}

Component

import dynamic from 'next/dynamic';

const Component = dynamic(()=> {
    const home =  import('homepage/Homepage')
    console.log(home)
}, {
    ssr: false,
    loading: () => <p>loading...</p>
})

const home = () => {
    return (
        <div>
            <Component />
        </div>
    )
}

export default home

It says,

  ⨯ ./src/pages/homepage.tsx:5:18
 Module not found: Can't resolve 'homepage/Homepage'
   3 |
   4 | const Component = dynamic(()=> {
 > 5 |     const home =  import('homepage/Homepage')
     |                  ^
   6 |     console.log(home)
   7 | }, {
   8 |     ssr: false,

@semonec
Copy link

semonec commented Mar 13, 2024

  • when I enable webpack config push in server case,
    it shows error like below
Import trace for requested module:
external "homepage@http://localhost:3001/remoteEntry.js"
remote homepage/Homepage
[ Module Federation Manifest Plugin ] Manifest Link: /_next/mf-manifest.json
 ⚠ external "homepage@http://localhost:3001/remoteEntry.js"
The generated code contains 'async/await' because this module is using "external script".
However, your target environment does not appear to support 'async/await'.
As a result, the code may not run as expected or may cause runtime errors.

@ScriptedAlchemy
Copy link
Member

Yeah when enabled server plugin push, that external warning is fine. It works.

@ScriptedAlchemy
Copy link
Member

@ScriptedAlchemy I'm on 5.12.7 and wanted to upgrade it to 8.2.2.

Getting below error with Module Not Found

image

I have next 13, react 18 installed.

Set env var like all my examples show on package json scripts. Next private local webpack or whatever it's called. That fixes serializeable error

@prakashmallow
Copy link

@ScriptedAlchemy I'm also facing the same issue with Nextjs 14.1.4 and module-federation 8.3.3

@Rajashekhar-Reddy
Copy link

Rajashekhar-Reddy commented Apr 27, 2024

Tried in ubuntu wsl, but still getting the same error

[email protected] dev cross-env NODE_ENV=development next dev -p 3001

ready - started server on 0.0.0.0:3001, url: http://localhost:3001 info - Loaded env from E:\work\app-store\.env NEXT_PUBLIC_BASE_PATH: undefined Error: Cannot find module 'E:\work\app-store\node_modules\next\dist\compiled\lib\util\makeSerializable'

Require stack:

  • E:\work\app-store\node_modules@module-federation\enhanced\dist\src\lib\container\ContainerExposedDependency.js
  • E:\work\app-store\node_modules@module-federation\enhanced\dist\src\lib\container\ContainerEntryModule.js
  • E:\work\app-store\node_modules@module-federation\enhanced\dist\src\lib\container\HoistContainerReferencesPlugin.js
  • E:\work\app-store\node_modules@module-federation\enhanced\dist\src\wrapper\HoistContainerReferencesPlugin.js
  • E:\work\app-store\node_modules@module-federation\enhanced\dist\src\index.js
  • E:\work\app-store\node_modules@module-federation\nextjs-mf\dist\src\internal.js
  • E:\work\app-store\node_modules@module-federation\nextjs-mf\dist\src\plugins\NextFederationPlugin\next-fragments.js
  • E:\work\app-store\node_modules@module-federation\nextjs-mf\dist\src\plugins\NextFederationPlugin\index.js
  • E:\work\app-store\node_modules@module-federation\nextjs-mf\dist\src\index.js
  • E:\work\app-store\next.config.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)

But suprisingly v8.1.3 works well but having a bulk of warnings

image

@shinyuna
Copy link

shinyuna commented Apr 28, 2024

Same error 🥲
image

  • next.js: 13.4.9
  • @module-federation/nextjs-mf: 8.3.9

👆 It works.

  • next.js: 14.2.3
  • @module-federation/nextjs-mf: 8.3.9

👆 It doesn't work. The next server is returning a 500 error.

@prakashmallow
Copy link

Same error 🥲 image

  • next.js: 13.4.9
  • @module-federation/nextjs-mf: 8.3.9

👆 It works.

  • next.js: 14.2.3
  • @module-federation/nextjs-mf: 8.3.9

👆 It doesn't work. The next server is returning a 500 error.

Try with @module-federation/nextjs-mf: 8.1.0 and next.js: 14.2.3.

@sreeharinm
Copy link

⚠ external "shop@http://localhost:3001/_next/static/chunks/remoteEntry.js"
The generated code contains 'async/await' because this module is using "external script".
However, your target environment does not appear to support 'async/await'.
As a result, the code may not run as expected or may cause runtime errors.

Import trace for requested module:
external "shop@http://localhost:3001/_next/static/chunks/remoteEntry.js"
remote shop/test

@HANYUNSEONG
Copy link

Same error 😢

  • next v12.2.4
  • @module-federation/nextjs-mf: 8.3.12
  • mac os

add NEXT_PRIVATE_LOCAL_WEBPACK=true line in .env.local

"dev": "rm -rf .next && NEXT_PRIVATE_LOCAL_WEBPACK=true next dev",

-> Error: Cannot find module /node_modules/next/dist/compiled/lib/util/makeSerializable

@ScriptedAlchemy
Copy link
Member

⚠ external "shop@http://localhost:3001/_next/static/chunks/remoteEntry.js"

The generated code contains 'async/await' because this module is using "external script".

However, your target environment does not appear to support 'async/await'.

As a result, the code may not run as expected or may cause runtime errors.

Import trace for requested module:

external "shop@http://localhost:3001/_next/static/chunks/remoteEntry.js"

remote shop/test

Not an error or issue.

@ScriptedAlchemy
Copy link
Member

Same error 😢

  • next v12.2.4

  • @module-federation/nextjs-mf: 8.3.12

  • mac os

add NEXT_PRIVATE_LOCAL_WEBPACK=true line in .env.local

"dev": "rm -rf .next && NEXT_PRIVATE_LOCAL_WEBPACK=true next dev",

-> Error: Cannot find module /node_modules/next/dist/compiled/lib/util/makeSerializable

Install webpack. Not sure if next 12 allows the override var or not.

@HANYUNSEONG
Copy link

HANYUNSEONG commented May 2, 2024

Same error 😢

  • next v12.2.4
  • @module-federation/nextjs-mf: 8.3.12
  • mac os

add NEXT_PRIVATE_LOCAL_WEBPACK=true line in .env.local
"dev": "rm -rf .next && NEXT_PRIVATE_LOCAL_WEBPACK=true next dev",
-> Error: Cannot find module /node_modules/next/dist/compiled/lib/util/makeSerializable

Install webpack. Not sure if next 12 allows the override var or not.

Thank you reply :)
I installed "webpack": "^5.91.0" in my project.
after, retry but same error 😭

@HANYUNSEONG
Copy link

Same error 😢

  • next v12.2.4
  • @module-federation/nextjs-mf: 8.3.12
  • mac os

add NEXT_PRIVATE_LOCAL_WEBPACK=true line in .env.local
"dev": "rm -rf .next && NEXT_PRIVATE_LOCAL_WEBPACK=true next dev",
-> Error: Cannot find module /node_modules/next/dist/compiled/lib/util/makeSerializable

Install webpack. Not sure if next 12 allows the override var or not.

Thank you reply :) I installed "webpack": "^5.91.0" in my project. after, retry but same error 😭

Resolved after version upgrade
nextjs 12.2.4 -> 13.5.6

@imarceloi
Copy link

⚠ external "shop@http://localhost:3001/_next/static/chunks/remoteEntry.js" The generated code contains 'async/await' because this module is using "external script". However, your target environment does not appear to support 'async/await'. As a result, the code may not run as expected or may cause runtime errors.

Import trace for requested module: external "shop@http://localhost:3001/_next/static/chunks/remoteEntry.js" remote shop/test

I'm receiving this same error here. Does someone knows how to fix this issue?

@haroldSanchezb
Copy link

Hi, I have expressjs with ts, webpack only for build bundles, and another project with commonjs and webpack i have this:

commonjs repo

const { UniversalFederationPlugin } = require('@module-federation/node');
[
    new UniversalFederationPlugin({
      name: 'remotelib',
      library: { type: 'commonjs-module' },
      isServer: true,
      remotes: {},
      filename: 'remoteEntry.js',
      useRuntimePlugin: true,
      exposes: {
        './calc': './src/util/calc',
      },
    }),
  ]

I use npx http-server for make available remoteEntry files

In my expressjs project:
init file

import { init } from '@module-federation/runtime';
init({
  name: 'app-main',
  remotes: [
    {
      name: 'remote-lib',
      entry: 'http://localhost:8080/remoteEntry.js',
      alias: 'remotelib',
    },
  ],
});

in mi app route:

import { loadRemote } from '@module-federation/runtime';
appRouter.get('/remote', async (req, res) => {
  console.log('remote');

  try {
    const remote = await loadRemote('remotelib/calc');
    const result = (remote as any).calc(1, 2);

    res.send(result);
  } catch (error: any) {
    console.error(error);
    res.send('Error');
  }
});

I don't know why im getting this error:

Error: Script execution error: Error: Cannot find module '/node_modules/@module-federation/sdk/dist/dist/index.cjs.js'
    at handleScriptFetch (/node_modules/@module-federation/sdk/dist/index.cjs.js:655:16)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

@mdadil09
Copy link

image

"@module-federation/nextjs-mf": "^8.2.0",
"next": "14.2.11",
"react": "^18",
"react-dom": "^18",
"webpack": "^5.94.0"

this is my next.config.js for app1
`const NextFederationPlugin = require("@module-federation/nextjs-mf");

module.exports = {
webpack(config, options) {
const { webpack } = options;
config.experiments = { topLevelAwait: true };

if (!options.isServer) {
  config.plugins.push(
    new NextFederationPlugin({
      name: "app1",
      remotes: {
        app2: app2@http://localhost:3001/_next/static/chunks/remoteEntry.js,
      },
      filename: "static/chunks/remoteEntry.js",
      exposes: {
        "./footer": "./components/Footer.js",
        "./nav": "./components/Nav.js",
      },
      shared: {},
      extraOptions: {},
    })
  );
}

return config;

},
};`

this is my next.config.js for app2

`const NextFederationPlugin = require("@module-federation/nextjs-mf");

module.exports = {
webpack(config, options) {
const { webpack } = options;
if (!options.isServer) {
config.plugins.push(
new NextFederationPlugin({
name: "app2",
remotes: {
app1: app1@http://localhost:3000/_next/static/chunks/remoteEntry.js,
},
filename: "static/chunks/remoteEntry.js",
exposes: {
"./catalog": "./components/Catalog.js",
},
shared: {},
extraOptions: {
exposePages: true,
},
})
);
}
config.cache = false;

return config;

},
};
`

this is where i am importing my remote component

`const NextFederationPlugin = require("@module-federation/nextjs-mf");

module.exports = {
webpack(config, options) {
const { webpack } = options;
if (!options.isServer) {
config.plugins.push(
new NextFederationPlugin({
name: "app2",
remotes: {
app1: app1@http://localhost:3000/_next/static/chunks/remoteEntry.js,
},
filename: "static/chunks/remoteEntry.js",
exposes: {
"./catalog": "./components/Catalog.js",
},
shared: {},
extraOptions: {
exposePages: true,
},
})
);
}
config.cache = false;

return config;

},
};
`

this is my package.json

{ "name": "app2", "version": "0.1.0", "private": true, "scripts": { "dev": "set NEXT_PRIVATE_LOCAL_WEBPACK=true && next dev -p 3001", "build": "set next telemetry disable && NEXT_PRIVATE_LOCAL_WEBPACK=true next build", "start": "set next start -p 3001", "lint": "next lint" }, "dependencies": { "@module-federation/nextjs-mf": "^8.2.0", "next": "14.2.11", "react": "^18", "react-dom": "^18", "webpack": "^5.94.0" }, "devDependencies": { "eslint": "^8", "eslint-config-next": "14.2.11", "postcss": "^8", "tailwindcss": "^3.4.1" } }

Please provide some fixes.

@minr2kb
Copy link

minr2kb commented Oct 25, 2024

For those struggling with the Error: Error: Cannot find module '<proj_dir>/node_modules/next/dist/compiled/lib/util/whatever'

  • next v14
  • @module-federation/nextjs-mf: 8.6.2
  • mac os

The key point, as mentioned in the README, is that the plugin should make Next.js use a webpack version installed via our package manager instead of Next.js’s built-in webpack. However, if you look inside the 'require stack' of the error message, you’ll see that it’s looking for webpack modules, but /node_modules/next/dist/... references a path within Next.js itself. This suggests that the webpack reference from the plugin is incorrect!

If you check Next.js’s built-in /node_modules/next/dist/compiled/webpack/webpack.js, you’ll notice that NEXT_PRIVATE_LOCAL_WEBPACK controls the webpack reference. This is why setting NEXT_PRIVATE_LOCAL_WEBPACK=true is essential. Next.js initializes its internal webpack while the server is starting, and it only reads the .env file later. So, setting it in .env alone won’t work. You need to define NEXT_PRIVATE_LOCAL_WEBPACK=true directly in package.json to ensure it’s set before webpack initializes.

tl;dr

  • Error: Cannot find module '<proj_dir>/node_modules/next/dist/compiled/lib/util/whatever' is due to an incorrect webpack reference.
  • "dev": "NEXT_PRIVATE_LOCAL_WEBPACK=true next dev"
  • "dev": "NEXT_PRIVATE_LOCAL_WEBPACK=true && next dev"
  • ❌ setting NEXT_PRIVATE_LOCAL_WEBPACK=true in .env

Etc.

  • If you’re still getting the same error even after modifying the script, the solution might be similar, but I’m not sure beyond this!
  • As for other module not found errors, I’m not really sure 🥲

@ScriptedAlchemy
Copy link
Member

image

"@module-federation/nextjs-mf": "^8.2.0",
"next": "14.2.11",
"react": "^18",
"react-dom": "^18",
"webpack": "^5.94.0"

this is my next.config.js for app1
`const NextFederationPlugin = require("@module-federation/nextjs-mf");

module.exports = {
webpack(config, options) {
const { webpack } = options;
config.experiments = { topLevelAwait: true };

if (!options.isServer) {
  config.plugins.push(
    new NextFederationPlugin({
      name: "app1",
      remotes: {
        app2: app2@http://localhost:3001/_next/static/chunks/remoteEntry.js,
      },
      filename: "static/chunks/remoteEntry.js",
      exposes: {
        "./footer": "./components/Footer.js",
        "./nav": "./components/Nav.js",
      },
      shared: {},
      extraOptions: {},
    })
  );
}

return config;

},
};`

this is my next.config.js for app2

`const NextFederationPlugin = require("@module-federation/nextjs-mf");

module.exports = {
webpack(config, options) {
const { webpack } = options;
if (!options.isServer) {
config.plugins.push(
new NextFederationPlugin({
name: "app2",
remotes: {
app1: app1@http://localhost:3000/_next/static/chunks/remoteEntry.js,
},
filename: "static/chunks/remoteEntry.js",
exposes: {
"./catalog": "./components/Catalog.js",
},
shared: {},
extraOptions: {
exposePages: true,
},
})
);
}
config.cache = false;

return config;

},
};
`

this is where i am importing my remote component

`const NextFederationPlugin = require("@module-federation/nextjs-mf");

module.exports = {
webpack(config, options) {
const { webpack } = options;
if (!options.isServer) {
config.plugins.push(
new NextFederationPlugin({
name: "app2",
remotes: {
app1: app1@http://localhost:3000/_next/static/chunks/remoteEntry.js,
},
filename: "static/chunks/remoteEntry.js",
exposes: {
"./catalog": "./components/Catalog.js",
},
shared: {},
extraOptions: {
exposePages: true,
},
})
);
}
config.cache = false;

return config;

},
};
`

this is my package.json

{ "name": "app2", "version": "0.1.0", "private": true, "scripts": { "dev": "set NEXT_PRIVATE_LOCAL_WEBPACK=true && next dev -p 3001", "build": "set next telemetry disable && NEXT_PRIVATE_LOCAL_WEBPACK=true next build", "start": "set next start -p 3001", "lint": "next lint" }, "dependencies": { "@module-federation/nextjs-mf": "^8.2.0", "next": "14.2.11", "react": "^18", "react-dom": "^18", "webpack": "^5.94.0" }, "devDependencies": { "eslint": "^8", "eslint-config-next": "14.2.11", "postcss": "^8", "tailwindcss": "^3.4.1" } }

Please provide some fixes.

You didn't apply plugin to server. But your import isn't wrapped in typeof window check. So server try to import the module you don't provide a remote for.

@ScriptedAlchemy
Copy link
Member

Support for next is ending

#3153

@module-federation module-federation locked and limited conversation to collaborators Nov 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
nextjs-mf nextjs-mf package identifier
Projects
None yet
Development

No branches or pull requests