Replies: 114 comments 140 replies
-
Furthermore, you can likely drop |
Beta Was this translation helpful? Give feedback.
-
Have the same issue |
Beta Was this translation helpful? Give feedback.
-
SOLVED: |
Beta Was this translation helpful? Give feedback.
-
Same issue, but with useRouter |
Beta Was this translation helpful? Give feedback.
-
For what it's worth, I was running into this same issue on Node 16.16.0, and upgrading to 18.5.0 resolved it. 🤷 |
Beta Was this translation helpful? Give feedback.
-
Got this error after upgrading the app from Next 13.1.6 to the latest Next 13.4.0, including some other dependencies, and deploying to Vercel:
Locally everything is perfect. Fails on Vercel. Made sure that local and remote Node version is 18. That didn't help. |
Beta Was this translation helpful? Give feedback.
-
I am still getting this error in 13.4.3 , however I am using turbo repo on top of it which seems to trigger the bug |
Beta Was this translation helpful? Give feedback.
-
Same error in next ^13.4.4 |
Beta Was this translation helpful? Give feedback.
-
Same error in Next 13.4.6 under Downgrading to Next 13.4.5 works |
Beta Was this translation helpful? Give feedback.
-
Had a same problem in 13.3.0, solved in 13.4.7. |
Beta Was this translation helpful? Give feedback.
-
Dealing with this extremely frustrating error for several days now. |
Beta Was this translation helpful? Give feedback.
-
I confirm this in 13.4.8, I downgraded to 13.4.5 and the same thing. |
Beta Was this translation helpful? Give feedback.
-
Out of curiosity are you using React Context? Or a library that uses React Context? |
Beta Was this translation helpful? Give feedback.
-
I faced the same issue and it was fixed in 13.4.7 version
|
Beta Was this translation helpful? Give feedback.
-
I have this issue right now, any solution? |
Beta Was this translation helpful? Give feedback.
-
Possible fix "use client"; //tells Next.js to render this component on the client
export { SessionProvider as AuthProvider } from 'next-auth/react' |
Beta Was this translation helpful? Give feedback.
-
Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ok bruh bruh bruh bruh bruh I am trying to use React and Next.JS to statically export it onto gh-pages and I am getting that error |
Beta Was this translation helpful? Give feedback.
-
I have tried most of the solutions suggested above and other than downgrading to an earlier version (13.5.6) from my current version (14.0.4) and pretty much nothing has worked - or even given me different errors. I encountered the issue midway through developing a new feature on a branched version of my app. Going back to my Unfortunately, none of the changes reproduced the error so I couldn't actually identify any specific patterns that would help. However, the new branch was buildable and deployable without the error. I'm not sure what this means, or if it helps anyone. It clearly not a sustainable "solution" but it is another piece in the puzzle... |
Beta Was this translation helpful? Give feedback.
-
In my case, I'm using so much libs in root package.json with yarn-berry based mono-repo. |
Beta Was this translation helpful? Give feedback.
-
same here i try to the flowing steps to fixed my case: 1, delete the i hope it will help someone |
Beta Was this translation helpful? Give feedback.
-
Changed from pnpm to npm, suddenly it works |
Beta Was this translation helpful? Give feedback.
-
Same with 2 projects, one big project and now with a new project I just created(today) |
Beta Was this translation helpful? Give feedback.
-
This fixed the issue for me: https://www.reddit.com/r/reactjs/comments/vl7ww2/comment/je62deh/ I was using pnpm and added the option
|
Beta Was this translation helpful? Give feedback.
-
I've had the same issue, and I found the root cause to be that I had multiple versions of react installed in my monorepo. I had
My current solution is to set my |
Beta Was this translation helpful? Give feedback.
-
TL;DR: mark your custom context files with "use client". I had a similar issue, caused by a custom context. I have my client-side providers stitched in a single file with "use client" at the top, but the context file itself did not have "use client." Adding "use client" to this custom context file resolved the issue. session-context.tsx "use client"; // <-- Added this
import { createContext, useContext, useEffect, useReducer } from "react";
import { me } from "@/lib/api/services/auth";
type SessionProps = {
authenticated?: boolean;
user?: {
id: string;
name: string;
email: string;
role: string;
type: string;
};
};
type SessionContextProps = {
state: SessionProps;
updateSession: (updatedData: SessionProps | Partial<SessionProps>) => void;
logout: () => void;
};
const Session = createContext<SessionContextProps | null>(null);
const reducer = (
state: SessionProps,
action: { type: string; payload?: SessionProps | Partial<SessionProps> },
) => {
switch (action.type) {
case "logout":
return { authenticated: false };
case "update":
return { ...state, ...action.payload };
default:
return state;
}
};
export const SessionProvider = ({ children }: { children: React.ReactNode }) => {
const [state, dispatch] = useReducer(reducer, {
authenticated: false,
});
const fetchUserUpdateSession = async () => {
try {
const user = await me();
dispatch({ type: "update", payload: { user, authenticated: true } });
} catch (error) {}
};
useEffect(() => {
fetchUserUpdateSession();
}, []);
const updateSession = (updatedData: SessionProps | Partial<SessionProps>) => {
dispatch({ type: "update", payload: updatedData });
};
const logout = () => {
dispatch({ type: "logout" });
};
return <Session.Provider value={{ state, updateSession, logout }}>{children}</Session.Provider>;
};
export const useSession = () => {
const context = useContext(Session);
return context;
}; client-providers.tsx "use client";
import { useState } from "react";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { SessionProvider } from "@/components/contexts/session-context";
type ClientProvidersProps = {
children: React.ReactNode;
};
export default function ClientProviders({ children }: ClientProvidersProps) {
const [queryClient] = useState(
() =>
new QueryClient({
defaultOptions: {
queries: {
staleTime: 60 * 1000,
},
},
}),
);
return (
<QueryClientProvider client={queryClient}>
<SessionProvider>{children}</SessionProvider>
</QueryClientProvider>
);
} And client-providers consumed in root layout export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en" suppressHydrationWarning>
<head />
<body className={cn("bg-background min-h-screen font-sans antialiased", poppins.variable)}>
<ThemeProvider
attribute="class"
defaultTheme="system"
enableSystem
disableTransitionOnChange
>
<ClientProviders>
{children}
<Toaster />
</ClientProviders>
</ThemeProvider>
</body>
</html>
);
} |
Beta Was this translation helpful? Give feedback.
-
All these pseudo-"solutions" are really placebo effects. This bug is pretty intermittent and hard to reproduce, it comes randomly with seemingly no cause, which at this point, I'm almost convinced either exists in Next.js core library or some of its dependencies that got updated in the recent months. |
Beta Was this translation helpful? Give feedback.
-
@clalexander posted a few weeks ago regarding observations around different versions of We have also been sporadically running into this issue, and are using What I found particularly interesting is, when using React Dev Tools, the inspection is showing a
This makes me question the state of the react dependencies within the lockfile, and leaves me curious as to why |
Beta Was this translation helpful? Give feedback.
-
My workspace had 2 projects with react as dependencies, on slightly different versions. I synced all versions up, installed and everything is back to normal. |
Beta Was this translation helpful? Give feedback.
-
Same problem here, no solution, if I try to change something in the code, the error message disappears, just recompiling the code hides this message. |
Beta Was this translation helpful? Give feedback.
-
this is a horrible error, i keep running into every now and again. |
Beta Was this translation helpful? Give feedback.
-
Verify canary release
Provide environment information
Which area of Next.js is affected? (leave empty if unsure)
Other
Link to reproduction - Issues with a link to complete (but minimal) reproduction code will be addressed faster
https://github.com/splashsaver/splashsaver.com
To Reproduce
yarn install
.yarn build
.Describe the Bug
Whenever I try to build my Turborepo project I get the following error.
TypeError: Cannot read properties of null (reading 'useContext')
More info:
I get the same error in my
web
app but with the respective paths, thedocs
app builds successfully.When I run the Turborepo project locally the page returns an
Internal Server Error
message and I get the following error.TypeError: Cannot read properties of null (reading 'useReducer')
Expected Behavior
Successful builds.
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Beta Was this translation helpful? Give feedback.
All reactions