gridsome/gridsome-starter-wordpress

Error: ECONNREFUSED - /wp-json/wp/v2/types

simduchaine opened this issue · 9 comments

When I'm running "gridsome explore" or "gridsome develop" commands, I get this error:

$ gridsome explore
Gridsome v0.6.6

Initializing plugins...
Initialize - 1.81s
Loading data from
Error: ECONNREFUSED - /wp-json/wp/v2/types
    at WordPressSource.fetch (B:\Projets\Dev\Websites\travel-blog-gridsome\node_modules\@gridsome\source-wordpress\index.js:168:15)
    at process._tickCallback (internal/process/next_tick.js:68:7)

I tried the endpoint /wp-json/wp/v2/types in my browser and in Postman and I was able to access the endpoint without any problem.

I'm having this same issue

Hi @simduchaine
Can you please provide your gridsome.config ?

I had the same error but I was giving the wrong baseUrl for my local Wordpress environment.

@Alligatore3 Here's my gridsome.config.js:

module.exports = {
  siteName: "Gridsome",
  siteDescription: "A WordPress starter for Gridsome",
  plugins: [
    {
      use: "@gridsome/source-wordpress",
      options: {
        baseUrl: process.env.WORDPRESS_URL, // required
        apiBase: "wp-json",
        typeName: "WordPress",
        perPage: 10,
        concurrent: 0,
        routes: {
          post: "/:year/:month/:day/:slug",
          post_tag: "/tag/:slug"
        }
      }
    }
  ]
};

And here's my ENV variable:
[template.environment] WORDPRESS_URL = "https://voyage.simonduchaine.com"

Note that I'm trying to fetch a live prod website not a local wordpress env.

@simduchaine
I'm not an expert with node env but I'm pretty sure that if you put your_path directly inside gridsome.config.js it works.

I tried with my remote env, I put my URL like this:
options: { baseUrl: 'https://voyage.simonduchaine.com', // required

Actually I got another error 😅 but at least not this one.

@Alligatore3 tried your suggestion, didn't get the ERCONNREFUSED but still, the issue is almost the same as now it's Graphql throwing a error 500 (try the gridsome explore command and you'll see).

I know this is quite a few months old but for someone else who might run into this issue I was able to solve it by adding a .env file and setting the WORDPRESS_URL= there.

I know this is quite a few months old but for someone else who might run into this issue I was able to solve it by adding a .env file and setting the WORDPRESS_URL= there.

What is the exact file name for the .env file you added? Is it just .env.json in root?

I know this is quite a few months old but for someone else who might run into this issue I was able to solve it by adding a .env file and setting the WORDPRESS_URL= there.

What is the exact file name for the .env file you added? Is it just .env.json in root?

The exact file name is .env it is called a dotfile. And yes you just put it at the root dir.

Using this theme as is, gridsome build fails when building the site on Netlify.

I thought, inside the netlify.toml file, the WORDPRESS_URL value should be set to the exact one specified in my .env file. However, that's not the case. (I'd appreciate some explanation why this fails. BTW, I also tried adding the exact json endpoint, too. Example: https://portal.mysite.com/wp-json)

I actually, had to remove the entire [template.environment] declaration from the netlify.toml file first.

Remove:

[template.environment]
  WORDPRESS_URL = "https://portal.mysite.com"

Then in my Netlify account, goto Settings > Build & Deploy > Environment Variables, add the same credentials from my .env file.

For example:

Key = WORDPRESS_URL
Value = https://portal.mysite.com

Now it works.