Hi,
Would appreciate any help with the following error when trying to run 'gatsby develop' after setting up the gatsby-source-wordpress following the official documentations:
The Error (in the terminal):
`error Plugin gatsby-source-wordpress returned an error
TypeError: Cannot read property 'request' of undefined
http-exception-handler.js:14 httpExceptionHandler
[wp-gatsby]/[gatsby-source-wordpress]/http-exception-handler.js:14:49
fetch.js:105
[wp-gatsby]/[gatsby-source-wordpress]/fetch.js:105:7
Generator.throw
util.js:16 tryCatcher
[lib]/[gatsby-cli]/[bluebird]/js/release/util.js:16:23
promise.js:512 Promise._settlePromiseFromHandler
[lib]/[gatsby-cli]/[bluebird]/js/release/promise.js:512:31
promise.js:569 Promise._settlePromise
[lib]/[gatsby-cli]/[bluebird]/js/release/promise.js:569:18
promise.js:614 Promise._settlePromise0
[lib]/[gatsby-cli]/[bluebird]/js/release/promise.js:614:10
promise.js:690 Promise._settlePromises
[lib]/[gatsby-cli]/[bluebird]/js/release/promise.js:690:18
async.js:138 _drainQueueStep
[lib]/[gatsby-cli]/[bluebird]/js/release/async.js:138:12
async.js:131 _drainQueue
[lib]/[gatsby-cli]/[bluebird]/js/release/async.js:131:9
async.js:147 Async._drainQueues
[lib]/[gatsby-cli]/[bluebird]/js/release/async.js:147:5
async.js:17 Immediate.Async.drainQueues
[lib]/[gatsby-cli]/[bluebird]/js/release/async.js:17:14
error UNHANDLED REJECTION
TypeError: Cannot read property 'filter' of undefined
api-runner-node.js:287 Promise.mapSeries.catch.then.results
[wp-gatsby]/[gatsby]/dist/utils/api-runner-node.js:287:42
util.js:16 tryCatcher
[wp-gatsby]/[bluebird]/js/release/util.js:16:23
promise.js:512 Promise._settlePromiseFromHandler
[wp-gatsby]/[bluebird]/js/release/promise.js:512:31
promise.js:569 Promise._settlePromise
[wp-gatsby]/[bluebird]/js/release/promise.js:569:18
promise.js:614 Promise._settlePromise0
[wp-gatsby]/[bluebird]/js/release/promise.js:614:10
promise.js:694 Promise._settlePromises
[wp-gatsby]/[bluebird]/js/release/promise.js:694:18
async.js:138 _drainQueueStep
[wp-gatsby]/[bluebird]/js/release/async.js:138:12
async.js:131 _drainQueue
[wp-gatsby]/[bluebird]/js/release/async.js:131:9
async.js:147 Async._drainQueues
[wp-gatsby]/[bluebird]/js/release/async.js:147:5
async.js:17 Immediate.Async.drainQueues
[wp-gatsby]/[bluebird]/js/release/async.js:17:14`
It seems that the source configuration is not correct, you should give a little more detail to reproduce the error.
Thanks devrchancay!
Hope this info might help:
============================================================
I have setup a local Wordpress installation with MAMP (the database named 'gatsby-tutorial').
Inside the Wordpress folder I created a wp-gatsby folder with the gatsby installation.
============================================================
My gatsby.config.js looks like this:
// gatsby.config.js
module.exports = {
siteMetadata: {
title: 'Wordpress Gatsby',
subtitle: `Data fetched from a site hosted on wordpress.com`,
},
plugins: [
'gatsby-plugin-react-helmet',
{
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.
},
},
'gatsby-plugin-offline',
{
resolve: `gatsby-source-wordpress`,
options: {
baseUrl: `www.localhost:8888/gatsby-tutorial/`,
protocol: `http`,
hostingWPCOM: false,
useACF: true,
},
},
],
}
====================================================================
My gatsby-node.js looks like this:
// gatsby-node.js
const _ = require(`lodash`);
const Promise = require(`bluebird`);
const path = require(`path`);
const slash = require(`slash`);
const pageQuery = `
{
allWordpressPage {
edges {
node {
id
slug
status
template
}
}
}
}
`
const postsQuery = `
{
allWordpressPost {
edges {
node {
id
slug
status
template
format
}
}
}
}
`
exports.createPages = ({ graphql, boundActionCreators }) => {
const { createPage } = boundActionCreators;
return new Promise((resolve, reject) => {
graphql(pageQuery)
.then(result => {
if (result.errors) {
console.log(result.errors);
reject(result.errors);
}
const pageTemplate = path.resolve("./src/templates/page.js");
_.each(result.data.allWordpressPage.edges, edge => {
createPage({
path: `/${edge.node.slug}/`,
component: slash(pageTemplate),
context: {
id: edge.node.id,
},
});
});
})
.then(() => {
graphql(postsQuery)
.then(result => {
if (result.errors) {
console.log(result.errors);
reject(result.errors);
}
const postTemplate = path.resolve("./src/templates/post.js");
_.each(result.data.allWordpressPost.edges, edge => {
createPage({
path: `/post/${edge.node.slug}/`,
component: slash(postTemplate),
context: {
id: edge.node.id,
},
});
});
resolve();
});
});
// ==== END POSTS ====
});
};
========================================================
My package.json look like this:
// package.json
{
"name": "gatsby-starter-default",
"description": "Gatsby default starter",
"version": "1.0.0",
"author": "Kyle Mathews <[email protected]>",
"dependencies": {
"gatsby": "^2.0.19",
"gatsby-plugin-manifest": "^2.0.5",
"gatsby-plugin-offline": "^2.0.5",
"gatsby-plugin-react-helmet": "^3.0.0",
"gatsby-source-wordpress": "^3.0.6",
"react": "^16.5.1",
"react-dom": "^16.5.1",
"react-helmet": "^5.2.0"
},
"keywords": [
"gatsby"
],
"license": "MIT",
"scripts": {
"build": "gatsby build",
"develop": "gatsby develop",
"format": "prettier --write '**/*.js'",
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {
"prettier": "^1.14.2"
},
"repository": {
"type": "git",
"url": "https://github.com/gatsbyjs/gatsby-starter-default"
}
}
========================================================
great, I get home I will try to replicate the error in my computer.
Thank you so much devrchancay!! much appreciated.
I'm seeing the same error and have traced it back to the use of "localhost" as the baseUrl. In the meantime I'm simply using non-localhost instances for testing, but it would be more convenient to have localhost support.
FYI - I've routed it through port 80 as well to see if that's the issue and I get the same errors.
Hi @k-tests,
I ran into the same TypeErrors as you and eventually came across this in the _Troubleshooting_ section at the bottom of the gatsby-source-wordpress docs:
When running locally, or in other situations that may involve self-signed certificates, you may run into the error: The request failed with error code
"DEPTH_ZERO_SELF_SIGNED_CERT".To solve this, you can disable Node.js’ rejection of unauthorized certificates by adding the following to gatsby-node.js:
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"
The errors didn't match, but I decided to try it anyway, and... it worked 🎉
Hopefully this solution resolves your issue as well.
Setting aside the specific issues raised above, the http-exception-handler.js plucks e.response and attempts to use it before checking it exists. The existence check then happens on the following line, so it makes debugging errors thrown a bit more difficult, as the error shown in the output is cannot read property "request" of undefined.
I've got the same error. Try to add baseUrl from your gatsby-source-wordpress options to your hosts file.
Hiya!
This issue has gone quiet. Spooky quiet. 👻
We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here.
If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!
Thanks for being a part of the Gatsby community! 💪💜
Hey again!
It’s been 30 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it.
Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m HUMAN_EMOTION_SORRY. Please feel free to reopen this issue or create a new one if you need anything else.
Thanks again for being part of the Gatsby community!
Hi @k-tests,
I ran into the same TypeErrors as you and eventually came across this in the _Troubleshooting_ section at the bottom of the
gatsby-source-wordpressdocs:When running locally, or in other situations that may involve self-signed certificates, you may run into the error: The request failed with error code
"DEPTH_ZERO_SELF_SIGNED_CERT".
To solve this, you can disable Node.js’ rejection of unauthorized certificates by adding the following to gatsby-node.js:
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"The errors didn't match, but I decided to try it anyway, and... it worked 🎉
Hopefully this solution resolves your issue as well.
Hi @jackpendleton,
I am facing the same issue and can't seem to solve it. I added dotenv via npm and created a .env.development file as specified in the doc. Could you please show an extract of your your gatsby-node.js file to see how to integrate the process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"?
I've got the same error. Try to add
baseUrlfrom your gatsby-source-wordpress options to your hosts file.
What exactly is my "host file"? Can you be more specific, please? Thanks.
Most helpful comment
Hi @k-tests,
I ran into the same TypeErrors as you and eventually came across this in the _Troubleshooting_ section at the bottom of the
gatsby-source-wordpressdocs:The errors didn't match, but I decided to try it anyway, and... it worked 🎉
Hopefully this solution resolves your issue as well.