#Error: NEXT_NOT_FOUND
1 messages · Page 1 of 1 (latest)
The NEXT_NOT_FOUND error is thrown when you invoke the notFound() function from 'next/navigation'. This function is used to render a Not Found UI within a route segment and terminate the rendering of the route segment in which it was thrown.
In your case, the error is being thrown because the condition params.lang !== locale is being met. This means that the language parameter from the URL does not match the locale being used, and as a result, the notFound() function is being called.
The notFound() function does not require you to use return notFound() due to using the TypeScript never type. So, the error you're seeing is expected behavior when the notFound() function is called.
If you're seeing this error and you didn't expect the notFound() function to be called, you should check the condition params.lang !== locale. Make sure that params.lang and locale have the values you expect.
Here is the relevant extract from the documentation:
import { notFound } from 'next/navigation'
async function fetchUsers(id) {
const res = await fetch('<https://...'>)
if (!res.ok) return undefined
return res.json()
}
export default async function Profile({ params }) {
const user = await fetchUser(params.id)
if (!user) {
notFound()
}
// ...
}
Source: Next.js Documentation (https://nextjs.org/docs/app/api-reference/functions/not-found)
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@idle ermine kapa.ai is still learning and improving, please let us how it did by reacting below
Let me check the knowledge base for you. One moment! :books:
No, the notFound function from 'next/navigation' cannot be set as default. The notFound function is a named export from the 'next/navigation' module, and it needs to be imported using its specific name.
Here is the correct way to import it:
import { notFound } from 'next/navigation'
Setting it as default would imply that it's the only or main export from the 'next/navigation' module, which is not the case. The 'next/navigation' module also exports other functions like redirect.