【发布时间】:2022-02-13 00:51:51
【问题描述】:
使用 Nextjs,我在 /pages 目录中创建了一个 index.js,并在 /components/meta/ 目录中创建了 meta.js。
当我的应用程序重建时,我收到以下错误:
元素类型无效:应为字符串(用于内置组件)或类/函数(用于复合组件)但得到:未定义。
如下所示,我正确导入了 Meta,它也是默认导出。好奇我哪里错了。
pages/index.js
// import Head from 'next/head'
import Meta from '../components/meta/meta';
export default () => (
<div>
<Meta />
<p>Hello world! Welcome to</p>
<h1>Moonholdings.io</h1>
</div>
)
components/meta/meta.js
import Head from 'next/head'
export default () => (
<Head>
<title>Moonholdings.io</title>
<meta name="description" content="Your Cryptocurrency Portfolio" />>
<meta name="keywords" content="cryptocurrency, crypto, portfolio, bitcoin, ethereum, holdings"/>
<meta name="robots" content="index, follow" />
<meta name="viewport" content="initial-scale=1.0, width=device-width" />
</Head>
)
项目结构
【问题讨论】:
标签: javascript node.js reactjs next.js react-component