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

Shared module next/router doesn't exist in shared scope default #1579

Closed
AmineAyachi opened this issue Oct 26, 2023 · 12 comments
Closed

Shared module next/router doesn't exist in shared scope default #1579

AmineAyachi opened this issue Oct 26, 2023 · 12 comments

Comments

@AmineAyachi
Copy link

In my next js turbor repo i have a host app with this next.config.js :

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

const nextConfig = {
  reactStrictMode: true,
  transpilePackages: ["ui", "core"],
  webpack: (config, options) => {
    const { isServer } = options;
    config.experiments = { topLevelAwait: true };
    config.plugins.push(
      new NextFederationPlugin({
        name: "application",
        remotes: {
          firstapplication:`firstapplication@http://localhost:4001/_next/static/${isServer ? 'ssr' : 'chunks'}/remoteEntry.js`,
          secondapplication:`secondapplication@http://localhost:4002/_next/static/${isServer ? 'ssr' : 'chunks'}/remoteEntry.js`,
        },
        shared:{
          i18next:{
              singleton:true
           },
        
          },
        filename: "static/chunks/remoteEntry.js",
        extraOptions: {
          exposePages: false,
        },
      })
    );
    return config;
  },
};

module.exports = nextConfig;

And when i use

import {useRouter} from 'next/router';

in my index.js file in pages i got this error :

Error: Shared module next/router doesn't exist in shared scope default

Note : I wanna use a next/router only in the host app and this error happens when I start the host app not the remotes it has nothing to do with the remotes and if I remove the import, the error disappear

@codal-Jamie
Copy link

Also running into this issue with my NextJS app running 13.5.6. I've found downgrading to an older version resolves the issue but I'm constrained by other NextJS bugs to keep running 13.5.6.

@RexGalicie
Copy link

@ScriptedAlchemy yeah faced same with Next 14 and nextjs-mf 8.1-cannary, during test process

@ScriptedAlchemy
Copy link
Member

what downgraded version works for you?

@ScriptedAlchemy
Copy link
Member

Please supply reproducible repo

@AmineAyachi
Copy link
Author

AmineAyachi commented Nov 4, 2023

Well i found a workaround which is using next/navigation instead of using next/router i will share with you the repo as soon as possible

@ScriptedAlchemy
Copy link
Member

are you using app directory? or pages directory?

@AmineAyachi
Copy link
Author

pages , "next": "^13.4.19",

@ScriptedAlchemy
Copy link
Member

do you have a reproducable example?

@ScriptedAlchemy
Copy link
Member

Should be resolved in latest canary releases

@codal-Jamie
Copy link

@ScriptedAlchemy Do you know when we can see these changes in a full release?

@nguyenthanhan201
Copy link

i fixed that error with update version ("next": "^13.1.1" -> "next": "13.4.7")

@ScriptedAlchemy
Copy link
Member

#2002

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants