Netlify部署具有TypeError的结果:无法读取未定义的属性“数据" [英] Netlify deploy with results of TypeError: Cannot read property 'data' of undefined

查看:83
本文介绍了Netlify部署具有TypeError的结果:无法读取未定义的属性“数据"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Wordpress作为无头CMS完成了我的项目,这项工作在本地完成;但是,当部署到netlify时,我无法获取"TypeError:无法读取未定义的属性'replace'"

I have completed my project using Wordpress as a headless CMS, this work locally; however when deploying to netlify I am getting cannot "TypeError: Cannot read property 'replace' of undefined"

该错误正在引用我的节点文件,该文件包含在下面.

The Error is referencing my node file, which is included below.

我尝试更改配置文件,更新程序包,并已在本地检查了所有内容.本地一切正常,我的活动服务器也正常运行,在尝试部署之前,我已迁移服务器.

I have tried changing my config file, updating my packages, and have reviewed everything locally. Everything works fine locally, and my live server is up and running fine as well, I migrated my server prior to attempting to deploy.

Netlify构建过程和错误日志

Netlify Build Process and Error Log

2:14:44 PM: Build ready to start
2:14:47 PM: build-image version: 9e0f207a27642d0115b1ca97cd5e8cebbe492f63
2:14:47 PM: build-image tag: v3.3.2
2:14:47 PM: buildbot version: ef8d0929ed0baabafd8bbb7d0b021e1fc24180c0
2:14:47 PM: Fetching cached dependencies
2:14:47 PM: Starting to download cache of 255.0KB
2:14:47 PM: Finished downloading cache in 84.166898ms
2:14:47 PM: Starting to extract cache
2:14:47 PM: Failed to fetch cache, continuing with build
2:14:47 PM: Starting to prepare the repo for build
2:14:47 PM: No cached dependencies found. Cloning fresh repo
2:14:47 PM: git clone https://github.com/rstowe1/wp-portfolio
2:14:48 PM: Preparing Git Reference refs/heads/master
2:14:48 PM: Starting build script
2:14:48 PM: Installing dependencies
2:14:50 PM: Downloading and installing node v10.16.3...
2:14:51 PM: Downloading https://nodejs.org/dist/v10.16.3/node-v10.16.3-linux-x64.tar.xz...
2:14:51 PM:   0
2:14:51 PM: .0%
2:14:51 PM: #
2:14:51 PM: #
2:14:51 PM: 3
2:14:51 PM: .
2:14:51 PM: 6
2:14:51 PM: %
2:14:51 PM: #
2:14:51 PM: #
2:14:51 PM: #
2:14:51 PM: #
2:14:51 PM: #
2:14:51 PM: #
2:14:51 PM: 9
2:14:51 PM: .
2:14:51 PM: 2
2:14:51 PM: %
2:14:51 PM: #
2:14:51 PM: #
2:14:51 PM: #
2:14:51 PM: #
2:14:51 PM: #
2:14:51 PM: #
2:14:51 PM: #
2:14:51 PM: #
2:14:51 PM:  12.4%
2:14:51 PM: 
############
2:14:51 PM:                                  17.0%
2:14:52 PM: 
##############
2:14:52 PM:  20.1%
2:14:52 PM: 
################
2:14:52 PM:                                              22.4%
2:14:52 PM: 
##################
2:14:52 PM:      26.3%
2:14:52 PM: 
####################
2:14:52 PM:  28.9%
2:14:52 PM: #
2:14:52 PM: #
2:14:52 PM: #
2:14:52 PM: #
2:14:52 PM: #
2:14:52 PM: #
2:14:52 PM: #
2:14:52 PM: #
2:14:52 PM: #
2:14:52 PM: #
2:14:52 PM: #
2:14:52 PM: #
2:14:52 PM: #
2:14:52 PM: #
2:14:52 PM: #
2:14:52 PM: #
2:14:52 PM: #
2:14:52 PM: #
2:14:52 PM: #
2:14:52 PM: #
2:14:52 PM: #
2:14:52 PM: 3
2:14:52 PM: 0
2:14:52 PM: .
2:14:52 PM: 5
2:14:52 PM: %
2:14:52 PM: 
######################
2:14:52 PM: #                                                   32.0%
2:14:52 PM: 
########################
2:14:52 PM:                           33.4%
2:14:52 PM: 
########################
2:14:52 PM:                                         34.5%
2:14:52 PM: 
#########################
2:14:52 PM:  35.7%
2:14:53 PM: 
#########################
2:14:53 PM:      36.1%
2:14:53 PM: 
###########################
2:14:53 PM:                         38.6%
2:14:53 PM: 
############################
2:14:53 PM:        39.9%
2:14:53 PM: 
#############################
2:14:53 PM:                                              41.6%
2:14:53 PM: 
###############################
2:14:53 PM:                               43.5%
2:14:53 PM: 
################################
2:14:53 PM:              45.4%
2:14:53 PM: 
#################################
2:14:53 PM:  47.1%
2:14:53 PM: 
###################################
2:14:53 PM:                                49.0%
2:14:53 PM: 
####################################
2:14:53 PM:                                      50.9%
2:14:53 PM: 
#####################################                                     52.3%
2:14:54 PM: #
2:14:54 PM: #
2:14:54 PM: #
2:14:54 PM: #
2:14:54 PM: ############
2:14:54 PM: #
2:14:54 PM: #################
2:14:54 PM: ####
2:14:54 PM:  5
2:14:54 PM: 3.6%
2:14:54 PM: 
###########################
2:14:54 PM: ############                                   55.3%
2:14:54 PM: 
#########################################
2:14:54 PM:                     57.0%
2:14:54 PM: 
##########################################                                58.8%
2:14:54 PM: 
###########################################
2:14:54 PM:            60.7%
2:14:54 PM: 
#############################################
2:14:54 PM:  62.8%
2:14:54 PM: 
#############################################
2:14:54 PM: #                            65.0%
2:14:54 PM: 
################################################
2:14:54 PM:  67.3%
2:14:54 PM: 
##################################################
2:14:54 PM:    70.5%
2:14:55 PM: 
####################################################
2:14:55 PM:               73.2%
2:14:55 PM: 
######################################################
2:14:55 PM:  76.1%
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: 7
2:14:55 PM: 9
2:14:55 PM: .
2:14:55 PM: 1
2:14:55 PM: %
2:14:55 PM: 
###################################
2:14:55 PM: ########################               82.2%
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: ####################             85.6%
2:14:55 PM: 
##########################
2:14:55 PM: ####################################            86.3%
2:14:55 PM: 
#####################
2:14:55 PM: ###############################################      94.9%
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: ###################
2:14:55 PM: ########################    97.6%
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: #
2:14:55 PM: ################################################################# 100.0%
2:14:56 PM: Computing checksum with sha256sum
2:14:56 PM: Checksums matched!
2:14:59 PM: Now using node v10.16.3 (npm v6.9.0)
2:14:59 PM: Attempting ruby version 2.6.2, read from environment
2:15:01 PM: Using ruby version 2.6.2
2:15:01 PM: Using PHP version 5.6
2:15:01 PM: Started restoring cached node modules
2:15:01 PM: Finished restoring cached node modules
2:15:01 PM: Installing NPM modules using NPM version 6.9.0
2:15:43 PM: > sharp@0.22.1 install /opt/build/repo/node_modules/sharp
2:15:43 PM: > (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)
2:15:43 PM: info
2:15:43 PM: sharp
2:15:43 PM:  Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.7.4/libvips-8.7.4-linux-x64.tar.gz
2:15:46 PM: > core-js@2.6.9 postinstall /opt/build/repo/node_modules/core-js
2:15:46 PM: > node scripts/postinstall || echo "ignore"
2:15:46 PM: Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!
2:15:46 PM: The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 
2:15:46 PM: > https://opencollective.com/core-js 
2:15:46 PM: > https://www.patreon.com/zloirock 
2:15:46 PM: Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)
2:15:46 PM: > core-js-pure@3.1.4 postinstall /opt/build/repo/node_modules/core-js-pure
2:15:46 PM: > node scripts/postinstall || echo "ignore"
2:15:47 PM: Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!
2:15:47 PM: The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 
2:15:47 PM: > https://opencollective.com/core-js 
2:15:47 PM: > https://www.patreon.com/zloirock 
2:15:47 PM: Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)
2:15:47 PM: > gatsby-telemetry@1.1.7 postinstall /opt/build/repo/node_modules/gatsby-telemetry
2:15:47 PM: > node src/postinstall.js
2:15:47 PM: > cwebp-bin@5.1.0 postinstall /opt/build/repo/node_modules/cwebp-bin
2:15:47 PM: > node lib/install.js
2:15:48 PM:   ✔ cwebp pre-build test passed successfully
2:15:48 PM: > mozjpeg@6.0.1 postinstall /opt/build/repo/node_modules/mozjpeg
2:15:48 PM: > node lib/install.js
2:15:48 PM:   ✔ mozjpeg pre-build test passed successfully
2:15:48 PM: > pngquant-bin@5.0.2 postinstall /opt/build/repo/node_modules/pngquant-bin
2:15:48 PM: > node lib/install.js
2:15:49 PM:   ✔ pngquant pre-build test passed successfully
2:15:49 PM: > styled-components@4.3.2 postinstall /opt/build/repo/node_modules/styled-components
2:15:49 PM: > node ./scripts/postinstall.js || exit 0
2:15:49 PM: Use styled-components at work? Consider supporting our development efforts at https://opencollective.com/styled-components
2:15:53 PM: npm WARN
2:15:53 PM:  optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/fsevents):
2:15:53 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
2:15:53 PM: added 1883 packages from 1026 contributors and audited 31033 packages in 50.015s
2:15:53 PM: found 1 critical severity vulnerability
2:15:53 PM:   run `npm audit fix` to fix them, or `npm audit` for details
2:15:53 PM: NPM modules installed
2:15:53 PM: Started restoring cached go cache
2:15:53 PM: Finished restoring cached go cache
2:15:54 PM: unset GOOS;
2:15:54 PM: unset GOARCH;
2:15:54 PM: export GOROOT='/opt/buildhome/.gimme/versions/go1.12.linux.amd64';
2:15:54 PM: export PATH="/opt/buildhome/.gimme/versions/go1.12.linux.amd64/bin:${PATH}";
2:15:54 PM: go version >&2;
2:15:54 PM: export GIMME_ENV='/opt/buildhome/.gimme/env/go1.12.linux.amd64.env';
2:15:54 PM: go version go1.12 linux/amd64
2:15:54 PM: Installing missing commands
2:15:54 PM: Verify run directory
2:15:54 PM: Executing user command: gatsby build
2:15:58 PM: success open and validate gatsby-configs — 0.123
2:15:59 PM: success load plugins — 1.093
2:16:00 PM: success onPreInit — 0.020
2:16:00 PM: success delete html and css files from previous builds — 0.019
2:16:00 PM: success initialize cache — 0.018
2:16:00 PM: success copy gatsby files — 0.061
2:16:00 PM: success onPreBootstrap — 0.028
2:16:00 PM: info Creating GraphQL type definition for File
2:16:00 PM: The request failed with error code "ECONNREFUSED"
2:16:00 PM: error #11321 PLUGIN Cannot read property 'data' of undefined
2:16:00 PM: "gatsby-source-wordpress" threw an error while running the sourceNodes lifecycle:
2:16:00 PM: Cannot read property 'data' of undefined
2:16:00 PM: See our docs page for more info on this error: https://gatsby.dev/issue-how-to
2:16:00 PM: 
2:16:00 PM:   TypeError: Cannot read property 'data' of undefined
2:16:00 PM:   
2:16:00 PM:   - fetch.js:141 fetch
2:16:00 PM:     [repo]/[gatsby-source-wordpress]/fetch.js:141:21
2:16:00 PM:   
2:16:00 PM:   - next_tick.js:68 process._tickCallback
2:16:00 PM:     internal/process/next_tick.js:68:7
2:16:00 PM:   
2:16:00 PM: 
2:16:00 PM: Skipping functions preparation step: no functions directory set
2:16:00 PM: Caching artifacts
2:16:00 PM: Started saving node modules
2:16:00 PM: Finished saving node modules
2:16:00 PM: Started saving pip cache
2:16:00 PM: Finished saving pip cache
2:16:00 PM: Started saving emacs cask dependencies
2:16:00 PM: Finished saving emacs cask dependencies
2:16:00 PM: Started saving maven dependencies
2:16:00 PM: Finished saving maven dependencies
2:16:00 PM: Started saving boot dependencies
2:16:00 PM: Finished saving boot dependencies
2:16:00 PM: Started saving go dependencies
2:16:00 PM: Finished saving go dependencies
2:16:04 PM: Error running command: Build script returned non-zero exit code: 1
2:16:04 PM: Failing build: Failed to build site
2:16:04 PM: failed during stage 'building site': Build script returned non-zero exit code: 1
2:16:04 PM: Finished processing build request in 1m17.398214412s

Gatsby-Node.js

Gatsby-Node.js

const _ = require(`lodash`)
const Promise = require(`bluebird`)
const path = require(`path`)
const slash = require(`slash`)

exports.createPages = ({ graphql, actions }) => {
  const { createPage } = actions
  // createRedirect({ fromPath: "/", toPath: "/home", redirectInBrowser: true, isPermanent: true })
  return new Promise((resolve, reject) => {
    // ==== PAGES (WORDPRESS NATIVE) ====
    graphql(
      `
        {
          allWordpressPage {
            edges {
              node {
                id
                slug
                status
                template
                title
                content
                template
              }
            }
          }
        }
      `,
    )
      .then(result => {
        if (result.errors) {
          console.log(result.errors)
          reject(result.errors)
        }

        const pageTemplate = path.resolve("./src/templates/page.js")
        const portfolioUnderContentTemplate = path.resolve("./src/templates/portfolioUnderContent.js")
        _.each(result.data.allWordpressPage.edges, edge => {

          createPage({
            path: `/${edge.node.slug}/`,
            component: slash(edge.node.template === "portfolio_under_content.php" ? portfolioUnderContentTemplate : pageTemplate),
            context: edge.node,
          })
        })
      })
      // ==== END PAGES ====

      // ==== PORTFOLIO ====
      .then(() => {
        graphql(
          `
            {
              allWordpressWpPortfolio{
                edges{
                  node{
                    id
                    title
                    slug
                    excerpt
                    content
                    featured_media{
                      source_url
                    }
                    acf{
                      portfolio_url
                    }
                  }
                }
              }
            }
          `,
        ).then(result => {
          if (result.errors) {
            console.log(result.errors)
            reject(result.errors)
          }
          const portfolioTemplate = path.resolve("./src/templates/portfolio.js")
          _.each(result.data.allWordpressWpPortfolio.edges, edge => {
            createPage({
              path: `/portfolio/${edge.node.slug}/`,
              component: slash(portfolioTemplate),
              context: edge.node,
            })
          })
        })
      })
      // ==== END PORTFOLIO ====
      // ==== BLOG POSTS ====
      .then(() => {
        graphql(`
            {
              allWordpressPost{
                edges{
                  node{
                    excerpt
                    wordpress_id
                    date(formatString: "Do MMM YYYY HH:mm")
                    title
                    content
                    slug
                  }
                }
              }
            }
          `).then(result => {
          if (result.errors) {
            console.log(result.errors)
            reject(result.errors)
          }

          const posts = result.data.allWordpressPost.edges
          const postsPerPage = 2
          const numberOfPages = Math.ceil(posts.length / postsPerPage)
          const blogPostListTemplate = path.resolve("./src/templates/blogPostList.js")

          Array.from({ length: numberOfPages }).forEach((page, index) => {
            createPage({
              component: slash(blogPostListTemplate),
              path: index === 0 ? "/blog" : `/blog/${index + 1}`,
              context: {
                posts: posts.slice(index * postsPerPage, (index * postsPerPage) + postsPerPage),
                numberOfPages,
                currentPage: index + 1,
              },
            })
          })

          const pageTemplate = path.resolve("./src/templates/page.js")
          _.each(posts, (post) => {
            createPage({
              path: `/post/${post.node.slug}`,
              component: slash(pageTemplate),
              context: post.node,
            })
          })

          resolve()
        })
      })
  })
}

Gatsby-Config.js

Gatsby-Config.js

require('dotenv').config({
  path:'.env'
})

module.exports = {
  siteMetadata: {
    title: `Gatsby Default Starter`,
    description: `Kick off your next, great Gatsby project with this default starter. This barebones starter ships with the main Gatsby configuration files you might need.`,
    author: `@gatsbyjs`,
  },
  plugins: [
    `gatsby-plugin-styled-components`,
    `gatsby-plugin-react-helmet`,
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `images`,
        path: `${__dirname}/src/images`,
      },
    },
    `gatsby-transformer-sharp`,
    `gatsby-plugin-sharp`,
    {
      resolve: `gatsby-plugin-manifest`,
      options: {
        name: `gatsby-starter-default`,
        short_name: `starter`,
        start_url: `/`,
        background_color: `#663399`,
        theme_color: `#663399`,
        display: `minimal-ui`,
        icon: `src/images/gatsby-icon.png`, // This path is relative to the root of the site.
      },
    },
    {
      resolve: "gatsby-source-wordpress",
      options: {

        baseUrl: process.env.API_URL,
        protocol: process.env.API_PROTOCOL,
        hostingWPCOM: false,
        useACF: true,
        acfOptionPageIds: [],
        auth: {
          htaccess_user: "your-htaccess-username",
          htaccess_pass: "your-htaccess-password",
          htaccess_sendImmediately: false,
          wpcom_app_clientSecret: process.env.WORDPRESS_CLIENT_SECRET,
          wpcom_app_clientId: "54793",
          wpcom_user: "gatsbyjswpexample@gmail.com",
          wpcom_pass: process.env.WORDPRESS_PASSWORD,
          jwt_user: process.env.JWT_USER,
          jwt_pass: process.env.JWT_PASSWORD,
          jwt_base_path: "/jwt-auth/v1/token",
        },
        cookies: {},
        verboseOutput: false,
        perPage: 100,
        searchAndReplaceContentUrls: {
          sourceUrl: "https://source-url.com",
          replacementUrl: "https://replacement-url.com",
        },
        concurrentRequests: 10,
        includedRoutes: [
          "**/*/*/categories",
          "**/*/*/posts",
          "**/*/*/pages",
          "**/*/*/media",
          "**/*/*/tags",
          "**/*/*/taxonomies",
          "**/*/*/users",
          "**/*/*/menus",
          "**/*/*/portfolio",
        ],
        excludedRoutes: [],
        normalizer: function({ entities }) {
          return entities
        },
      },
    },
    'gatsby-plugin-netlify'
  ],
}

Package.json

Package.json

{
  "name": "gatsby-starter-default",
  "private": true,
  "description": "A simple starter to get up and developing quickly with Gatsby",
  "version": "0.1.0",
  "author": "Kyle Mathews <mathews.kyle@gmail.com>",
  "dependencies": {
    "@material-ui/core": "^4.3.0",
    "babel-plugin-styled-components": "^1.10.6",
    "gatsby": "^2.13.45",
    "gatsby-image": "^2.2.7",
    "gatsby-plugin-manifest": "^2.2.4",
    "gatsby-plugin-netlify": "^2.1.3",
    "gatsby-plugin-offline": "^2.2.4",
    "gatsby-plugin-react-helmet": "^3.1.2",
    "gatsby-plugin-sharp": "^2.2.9",
    "gatsby-plugin-styled-components": "^3.1.2",
    "gatsby-source-filesystem": "^2.1.7",
    "gatsby-source-wordpress": "^3.1.12",
    "gatsby-transformer-sharp": "^2.2.5",
    "prop-types": "^15.7.2",
    "react": "^16.8.6",
    "react-dom": "^16.9.0",
    "react-grid-system": "^4.4.11",
    "react-helmet": "^5.2.1",
    "styled-components": "^4.3.2"
  },
  "devDependencies": {
    "prettier": "^1.18.2"
  },
  "keywords": [
    "gatsby"
  ],
  "license": "MIT",
  "scripts": {
    "build": "gatsby build",
    "develop": "gatsby develop",
    "format": "prettier --write src/**/*.{js,jsx}",
    "start": "npm run develop",
    "serve": "gatsby serve",
    "test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\""
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/gatsbyjs/gatsby-starter-default"
  },
  "bugs": {
    "url": "https://github.com/gatsbyjs/gatsby/issues"
  }
}

我需要知道我在哪里搞砸了,以便可以修复和部署它.

I need to know where I messed up so that I can get this fixed and deployed.

对我的错误及其纠正方法的任何见解,将不胜感激.

any insight into my error and how to correct it will be greatly appreciated.

推荐答案

不确定您是否仍需要帮助,但是我遇到了同样的问题,尝试解决了数小时,才终于找到答案.如果您和我有同样的问题,那是因为您尝试将API(在这种情况下为无头Wordpress安装)移动到服务器,并且尚未在其中启用永久链接.如果这是问题所在,则可以在执行以下操作时检查本地WP安装是否返回了某些内容: YOUR_LOCAL_WP/wp-json/wp/v2/posts .如果可以,但是您托管的WP安装没有( HOSTED_WP/wp-json/wp/v2/posts ),您发现了问题.

Not sure whether you still need help, but I just ran into the same problem and tried solving it for hours before finally figuring it out. If you have the same problem as me, it's because you tried moving your API (in this case the headless Wordpress install) to a server and you haven't enabled permalinks there. If that is the problem you can check whether your local WP installation returns something when going to: YOUR_LOCAL_WP/wp-json/wp/v2/posts. If it does, but your hosted WP install does not (HOSTED_WP/wp-json/wp/v2/posts) you found your problem.

为了解决该问题,您可以简单地登录到您托管的WP安装下 HOSTED_WP/wp-admin ->设置->永久链接.在此处选择帖子名并保存您的更改.在保存更改"按钮下方,您将获得一个类似于以下内容的代码段:

In order to solve it you can simply log into your hosted WP install under HOSTED_WP/wp-admin -> settings -> permalinks. There you select post-name and save your changes. Below the Save Changes button you get a code snippet that looks something like this:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

通过WP安装登录到服务器,然后通过 cd 进入Web根文件夹来创建或添加到 .htaccess 文件.通常是在/var/www/html 中.将上面的代码段粘贴到您的.htaccess文件中后,您应该一切顺利!

Log into your server with the WP install and either create or add to your .htaccess file by cding into your web root folder. That is usually in /var/www/html. After pasting the above snippet into your .htaccess file, you should be good to go!

这篇关于Netlify部署具有TypeError的结果:无法读取未定义的属性“数据"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆