directus / gatsby-source-directus

Source plugin for pulling data into Gatsby from a Directus API.
10 stars 12 forks source link

gatsby-source-directus fails with Node 18 #12

Closed cdanny358 closed 1 year ago

cdanny358 commented 1 year ago

Gatsby 5 requires Node 18, but as soon as I upgrade Node from v16.18.1 to v18.12.1, gatsby-source-directus fails with this error:

"@directus/gatsby-source-directus" threw an error while running the createSchemaCustomization lifecycle:

gatsby-source-directus: authentication failed with: connect ECONNREFUSED ::1:8055
Are credentials valid?

In Node 16 this error doesn't occur, and the project builds properly. In gatsby-config.js, the plugin is configured like this:

    {
      resolve: '@directus/gatsby-source-directus',
      options: {
        url: 'http://localhost:8055',
        auth: {
          token: process.env.TOKEN
        }
      }
    }
cdanny358 commented 1 year ago

Update: this seems to be a problem only when Directus is hosted locally. Seems to work fine with Node 18 when Directus is hosted on a remote server. Might it have to do with http vs https?

cdanny358 commented 1 year ago

Update 2: Found the solution. It doesn't like localhost in the URL. Changing to the actual IP address of my computer, or even 127.0.0.1, fixes it. Apparently Node v17 and up resolves localhost to an IPv6 address rather than the IPv4 address of earlier Node versions.

azrikahar commented 1 year ago

Update 2: Found the solution. It doesn't like localhost in the URL. Changing to the actual IP address of my computer, or even 127.0.0.1, fixes it. Apparently Node v17 and up resolves localhost to an IPv6 address rather than the IPv4 address of earlier Node versions.

Thanks for the update! Bumped into the same issue in directus/examples#173 and instantly recalled your update here.