Next.js 服务器错误:元素类型无效:应为字符串
我在使用NextJS时遇到了这个错误Next.js 服务器错误:元素类型无效:应为字符串,next.js,Next.js,我在使用NextJS时遇到了这个错误 Server Error Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got:undefined. You likely forgot to export your component from the file it's defined in,
Server Error
Error: Element type is invalid: expected a string (for built-in components)
or a class/function (for composite components) but got:undefined. You likely
forgot to export your component from the file it's defined in, or you might
have mixed up default and named imports.
This error happened while generating the page. Any console logs will be displayed
in the terminal window.
资料来源:
pages\_document.tsx (86:33) @ Function.getInitialProps
84 | }
85 |
> 86 | const { html, head } = await ctx.renderPage({ enhanceApp })
| ^
87 | const styles = [...flush()]
88 | return { html, head, styles }
89 | }
我的代码:
函数MyApp({Component,pageProps,openSidebar,closeSidebar}){
常量[sidebarOpen,setSidebarOpen]=useState(false)
useffect(()=>{
常量openSidebar=()=>{
setSidebarOpen(正确);
};
const closeSidebar=()=>{
setSidebarOpen(假);
};
})
返回(
)
}
导出默认MyApp
这些是导入:导入“../style/globals.css”导入“./components/main/main.css”导入“./components/navbar/navbar.css”导入“./components/sidebar/sidebar.css”从“./components/main/main”导入main;从“./components/NavBar/NavBar”导入导航栏;从“./组件/侧边栏/侧边栏”导入侧边栏;从'react bootstrap'导入{Container}从'react'导入{useState,useEffect}