Npm run build error! Help! #48724
Replies: 9 comments 16 replies
-
Try this one. Open next.config.js and enable the ignoreBuildErrors option in the typescript config:
|
Beta Was this translation helpful? Give feedback.
-
EDIT: I see that people keep liking the dubious idea of ignoring typescript errors when the resolution of this problem is relatively straightforward. But maybe my original answer was as cryptic as the message. The gist of it is: don't export your functions or data from Next.js special files (pages, layouts and routes). Not even the page/layout component as a named export, only as the default export. After looking into the webpack plugin I discovered that this error is a (terribly cryptic) way of stating that a special file is exporting an identifier that is not included in the allowed exports. The list of allowed exports are the keys of the type defined here: next.js/packages/next/src/build/webpack/plugins/next-types-plugin.ts Lines 57 to 79 in 804ca09 |
Beta Was this translation helpful? Give feedback.
-
I was getting this error because I had defined export async function generateMetadata(
parent: ResolvingMetadata
): Promise<Metadata> { changing it to export async function generateMetadata(): Promise<Metadata> { fixed the problem. I don't remember why I added the |
Beta Was this translation helpful? Give feedback.
-
I received this error because I was exporting from my root layout page. Once I moved the code I needed to export out of the layout file and imported it instead, my issue went away. |
Beta Was this translation helpful? Give feedback.
-
You need to export default your component/page, I also facing this problem
It returns this error
Then I fixed it by simply export default the component on the page
|
Beta Was this translation helpful? Give feedback.
-
I got a similar error. I was using the name page.tsx to each component created in my project which NextJS was including them in the app router, so I solved that renaming the files to not include them in the router. That solved my problem. |
Beta Was this translation helpful? Give feedback.
-
export interface ColorModeContextType { // Create the context with a default value I was getting the same error in the above code for context, this code was declared inside the layout.tsx component. I moved this to a different file and exported it as default. |
Beta Was this translation helpful? Give feedback.
-
I saved mine simply by not having two exports in Next.js special files (pages, layouts, etc.). I moved my other export to a different file and imported from there which fixed my problem. |
Beta Was this translation helpful? Give feedback.
-
This solution was much easier than I thought; it didn't require any changes or additions to the code. Essentially, in Next.js, a The solution was simply to rename the files from:
to
Instead of |
Beta Was this translation helpful? Give feedback.
-
Summary
Hi, I'm trying to build my nextjs using appDir. The app works fine when runned on npm run dev but an error is thrown when I try to build it. Here is the error:
Code for my component:
Implementing my code and passing props:
Beta Was this translation helpful? Give feedback.
All reactions