next.js 尝试导入错误:“Navbar”未从“@/components/Navbar”导出(作为“Navbar”导入)

llmtgqce  于 2023-08-04  发布在  其他
关注(0)|答案(1)|浏览(240)

我想添加导航栏和页脚到我的nextjs项目,但我无法使用布局。这是我的文件结构。


的数据
代码如下:

import './globals.css'
import { Inter } from 'next/font/google'

import {Navbar} from '@/components/Navbar'
const inter = Inter({ subsets: ['latin'] })

export const metadata = {
  title: 'Create Next App',
  description: 'Generated by create next app',
}

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <Navbar />
      {/* hello */}
      <body className={inter.className}>{children}</body>
    </html>
  )
}

字符串
我遇到了一个错误:

Attempted import error: 'Navbar' is not exported from '@/components/Navbar' (imported as 'Navbar').

Import trace for requested module:
./src/app/layout.js
Warning: React.jsx: 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.

Check your code at layout.js:15.
- error node_modules\next\dist\compiled\react-server-dom-webpack\cjs\react-server-dom-webpack-server.edge.development.js (1684:8) @ attemptResolveElement
- error Error: Unsupported Server Component type: undefined
    at stringify (<anonymous>)


帮我解决这个问题

4ngedf3f

4ngedf3f1#

您很可能忘记在Navbar.tsx中export default您的Navbar函数
此外,导航栏组件应该在body内部。

相关问题