Gatsby无法工作在github页面上部署的路径在URL中添加回购名称

问题描述

我部署了一个带有Github页面的gatsby网站,但出现类似这样的错误

enter image description here

在本地,一切正常,仅在服务器上发生错误。 似乎服务器无法正确解析路径。 我在域后添加不必要的存储库名称。如何删除? 我尝试更改某些主机选项并再次部署应用程序,一旦IDK正常运行,为什么我又进行了一次部署又再次崩溃了。 我的gatsby.config

const path = require("path");
const { title,keywords,description,author,defaultLang,trackingId } = require("./config/site");

module.exports = {
  pathPrefix: "/lbearthworks",siteMetadata: {
    title,},plugins: [
    {
      resolve: "gatsby-plugin-google-analytics",options: {
        trackingId,{
      resolve: "gatsby-plugin-manifest",options: {
        name: title,short_name: "Lb",start_url: "/",background_color: "#212121",theme_color: "#fed136",display: "minimal-ui",icon: "content/assets/gatsby-icon.png","gatsby-transformer-remark",{
      resolve: "gatsby-source-filesystem",options: {
        name: "markdown",path: `${__dirname}/content`,options: {
        name: "images",path: `${__dirname}/content/assets/images`,"gatsby-plugin-eslint","gatsby-plugin-react-helmet","gatsby-transformer-sharp","gatsby-plugin-sharp","gatsby-plugin-offline",{
      resolve: "gatsby-plugin-sass",options: {
        data: `@import "core.scss";`,includePaths: [path.resolve(__dirname,"src/style")],...
  ],};

Live version

Github Reository

解决方法

在处理GitHub Pages时,由于要添加pathPrefix变量,因此需要在构建命令中添加额外的配置,因此需要允许Netlify如何为这些路径添加前缀。理想情况下,build命令应如下所示:

"deploy": "gatsby build --prefix-paths && gh-pages -d public"

在您的情况下,由于要添加基于文件的配置(netlify.toml),因此您的构建命令为:

[build]
  command = "yarn && yarn testbuild"
  publish = "public"

请注意,testbuildyarn test && yarn buildaccording to your repository

因此,一种解决方法是将您的package.json命令更改为:

"testbuild": "yarn test && yarn build --prefix-paths && gh-pages -d public",

此外,您应该在gh-pages分支中,因为它显示了Gatsby's documentation

运行npm run deploy时,公用文件夹的所有内容都将 已移至存储库的gh-pages分支。确保您的 存储库的设置将gh-pages分支设置为 部署。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...