reactjs - 尝试部署我的 Gatsby 站点时收到“props.children 不是函数”错误
问题描述
一直在阅读有关此问题的其他帖子,但无法弄清楚。在我的开发版本中一切正常,但 Netlify 在我尝试部署时抛出此错误:
4:58:48 PM: WebpackError: TypeError: props.children is not a function
4:58:48 PM:
4:58:48 PM: - layout.js:90
4:58:48 PM: src/components/layout.js:90:20
我的布局组件:
const Layout = props => {
const data = useStaticQuery(graphql`
query SiteTitleQuery {
site {
siteMetadata {
title
}
}
}
`)
...
const globals = {
about: about,
menu: menu,
closeMenu: () => toggleMenu(false),
song: song,
handleSongChange: handleSongChange,
videoLoop: videoLoop,
}
return (
<>
<Header
siteTitle={data.site.siteMetadata?.title || `Title`}
/>
<main>{props.children({ ...props, ...globals })}</main>
<Footer />
</>
)
}
export default Layout
在我的索引页面中使用布局:
const IndexPage = () => {
return (
...
<Layout>
{props => (
<>
//using props.menu, props.about, etc here
</>
)}
</Layout>
)
}
export default IndexPage
解决方案
听起来你有一个页面正在做这样的事情:
<Layout>Hi</Layout>
或这个:
<Layout />
在开发中,Gatsby 只为您提供您正在查看的页面。当您运行时gatsby build
,它将评估它正在构建的每个页面的代码,这很可能是您在构建时发现问题而不是在开发中发现问题的原因。
不过,您可能真的不打算为Layout
组件使用子功能配置。
推荐阅读
- arrays - 查看数组是否按降序排列时跳过数组中的特定数字
- reactjs - react bootstrap 上的列显示,尽管被声明为 2 列,但仅显示为 1 列
- java - spring 在哪里查找带有 @Value 注释的值
- python - 根据键拆分字典
- python - 如果它们包含子字符串,我将附加到新列表,如果不包含,则附加到新列表。第二个列表得到了第一个的条件,为什么?
- intellij-idea - 将 IntelliJ 的控制台输出通过管道传输到脚本
- docker - 运行没有入口点的命令
- python - 创建一个列,它是熊猫中两个字符串列的差异
- python - 如果输入不足,如何遍历文件并引发自定义异常?
- python - 如何对字符串列表中的元素进行编号并返回一个新列表?