首页 > 解决方案 > Gatsby 构建 html 内容为空

问题描述

我有一个在 Gatsby@2.2.10 完成的网站。当我运行gatsby build并检查生成的 html 时,对于每个页面,我看到的只是一个空的 div: <div id="___gatsby"></div。html 包含样式表、javascript 文件和运行应用程序所需的一切(顺便说一下)。

即使我curl是生产 url,也会出现相同的 div 并且完全为空。我还尝试禁用 javascript,但我得到的只是一个空白页。我的配置不包含任何花哨的内容:

module.exports = {
    siteMetadata: {
        title      : `MyApp`,
        description: ``,
        author     : ``,
    },
    plugins     : [
        `gatsby-plugin-react-helmet`,
        {
            resolve: `gatsby-source-filesystem`,
            options: {
                name: `images`,
                path: `${__dirname}/src/static/images`,
            },
        },
        {
            resolve: `gatsby-plugin-less`,
            options: {
                javascriptEnabled: true,
            },
        },
        `gatsby-transformer-sharp`,
        `gatsby-plugin-sass`,
        `gatsby-plugin-sharp`,
        `gatsby-plugin-typescript`,
        `gatsby-plugin-styled-components`,
        {
            resolve: `gatsby-plugin-google-fonts`,
            options: {
                fonts: [
                    `Montserrat\:200,400,600,800`,
                ],
            },
        },
        {
            resolve: `gatsby-plugin-manifest`,
            options: {
                name            : `MyApp.com`,
                short_name      : `MyApp`,
                start_url       : `/`,
                background_color: `#4DECDB`,
                theme_color     : `#2F57E4`,
                display         : `minimal-ui`,
                icon            : `src/static/images/logo.png`,
            },
        },
        `gatsby-plugin-offline`,
        {
            resolve: `gatsby-plugin-google-analytics`,
            options: {
                // replace "UA-XXXXXXXXX-X" with your own Tracking ID
                trackingId: 'UA-111111111-16',
            },
        },
        //  last
        'gatsby-plugin-netlify',
    ],
}

我的gatbsy-node文件是空的,gatsby-browser只加载了一个样式表和一个 redux 存储:

import wrapWithProvider from './wrap-wit-provider'

import './src/components/layout/styles.less'

export const wrapRootElement = wrapWithProvider

任何想法我应该寻找什么?除非 Netlify 由于不存在 html 代码而无法检测到我的表单并处理它们,否则我不会那么担心。

标签: javascriptgatsby

解决方案


我到这里在 gatsby build 上搜索“空白页”,在我的情况下,这个问题是一个愚蠢的问题,希望它对某人有所帮助。

如果public文件夹已被修改,或文件被移动,gatsby 将失败。只需删除整个文件夹并重建工作正常。


推荐阅读