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

Error: Placement of 'use client' Directive in Next.js App with nextjs-mf #953

Closed
PouryaTak opened this issue Jun 3, 2023 · 5 comments
Closed

Comments

@PouryaTak
Copy link

I am currently using nextjs-mf with nextjs version 13.4.4 and the App router. However, I am encountering an error when I utilize the "use client" directive in both the pages or components within the app directory. The error message I receive is as follows:

ReactServerComponentsError:
The "use client" directive must be placed before other expressions. Move it to the top of the file to resolve this issue.
 1 | 
 2 | require("./..\\..\\node_modules\\@module-federation\\nextjs-mf\\src\\include-defaults.js");
 3 | "use client"
    : ^^^^^^^^^^^^

I am seeking guidance on how to resolve this issue and make the necessary adjustments to rectify it.

@syedolive
Copy link

Any update on this?

@ScriptedAlchemy
Copy link
Member

Submit a PR and ill cut a new release, some users have found that adding "use client" to the top of this file resolves the issue.

I'm planning on releasing v7 of this plugin next week, I'm not sure I have include-defaults anymore but likely a similar directive needs to be added there as well.

nameofname pushed a commit to nameofname/universe that referenced this issue Jun 20, 2023
@nameofname
Copy link
Contributor

nameofname commented Jun 20, 2023

@ScriptedAlchemy I submitted a PR here :
https://github.com/module-federation/universe/pull/980/files

I'm not sure whether removing the patch on server builds is a proper solution. I noticed that you are not including the federation plugin for server builds in your example repo which is where I got the idea.

Hope this helps!

ScriptedAlchemy added a commit that referenced this issue Jun 22, 2023
Co-authored-by: Ron Williams <[email protected]>
Co-authored-by: Zack Jackson <[email protected]>
RussellCanfield pushed a commit to RussellCanfield/nextjs-mf that referenced this issue Jul 1, 2023
@ScriptedAlchemy
Copy link
Member

I have released v7 which changed the structure of this file, but i did add use client into the loader that patches this specific file so it should have same result

@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

4 participants