1

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 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

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

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

{
  "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.

ksav
  • 20,015
  • 6
  • 46
  • 66
rstowe1
  • 71
  • 1
  • 4
  • 14
  • 3
    Do you have `API_URL`, `API_PROTOCOL`, `WORDPRESS_CLIENT_SECRET`, `WORDPRESS_PASSWORD` `JWT_USER` `JWT_PASSWORD` defined in your Environment variables correctly? Error is `2:16:00 PM: The request failed with error code "ECONNREFUSED"` which means connection to the server did not establish correctly or rejected – Rikin Aug 26 '19 at 18:41
  • I have API Protocol and API URL set up correctly, the others were never used during development – rstowe1 Aug 27 '19 at 20:11
  • In that case it seems that you would need to get those from wordpress account in production, local may have separate config so hard to say on that. You can see in your config `auth` is needed to establish connection else you can remove it if not needed, which I doubt. – Rikin Aug 28 '19 at 15:04
  • I know this is not an answer but, When I deployed it again, It magically worked. – Appaji Chintimi Mar 16 '21 at 07:56

1 Answers1

0

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.

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>

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!

Nickfis
  • 168
  • 12