Skip to content

gatsby build fails – Unable to fetch: asset #24

@ghost

Description

That's my first github issue ever, so be patient with me :)

Upon running gatsby build i get the following console error, right after success createSchemaCustomization - 0.995s:

 ERROR #11321  API.NODE.EXECUTION

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

Unable to fetch:
http://0.0.0.0:8055/apiassets/fa38e044-7051-478f-bb3e-60a9203cad49
---
Reason: Response code 404 (Not Found)
---
Fetch details:
{
  "attempt": 3,
  "method": "GET",
  "errorCode": "ERR_NON_2XX_3XX_RESPONSE",
  "responseStatusCode": 404,
  "responseStatusMessage": "Not Found",
  "requestHeaders": {
    "user-agent": "got (https://github.com/sindresorhus/got)",
    "authorization": "Bearer XXX", #hidden ;)
    "accept-encoding": "gzip, deflate, br"
  },
  "responseHeaders": {
    "content-security-policy": "script-src 'self' 'unsafe-eval';worker-src 'self' blob:;child-src 'self' blob:;img-src 'self' data: blob: https://cdn.directus.io;media-src 'self' https://cdn.directus.io;connect-src 'self' https://*;default-src 'self';base-uri 'self';font-src 'self' https: data:;form-action 'self';frame-ancestors 'self';object-src
'none';script-src-attr 'none';style-src 'self' https: 'unsafe-inline'",
    "x-powered-by": "Directus",
    "vary": "Origin",
    "access-control-allow-credentials": "true",
    "access-control-expose-headers": "Content-Range",
    "content-type": "application/json; charset=utf-8",
    "content-length": "135",
    "etag": "W/\"87-z71CK3Cz69C2v+wQIOJA8Sei+HE\"",
    "date": "Wed, 19 Apr 2023 09:18:30 GMT",
    "connection": "keep-alive",
    "keep-alive": "timeout=5"
  }
}
---



  HTTPError: Response code 404 (Not Found)
  
  - index.js:913 Request._onResponseBase
    [frontend]/[got]/dist/source/core/index.js:913:31
  
  - index.js:948 Request._onResponse
    [frontend]/[got]/dist/source/core/index.js:948:24
  
  - index.js:962 ClientRequest.<anonymous>
    [frontend]/[got]/dist/source/core/index.js:962:23
  
  - node:events:628 Object.onceWrapper
    node:events:628:26
  
  - node:events:525 ClientRequest.emit
    node:events:525:35
  
  - index.js:43 ClientRequest.origin.emit
    [frontend]/[@szmarczak]/http-timer/dist/source/index.js:43:20
  
  - node:_http_client:693 HTTPParser.parserOnIncomingClient
    node:_http_client:693:27
  
  - node:_http_common:119 HTTPParser.parserOnHeadersComplete
    node:_http_common:119:17
  
  - node:_http_client:535 Socket.socketOnData
    node:_http_client:535:22
  
  - node:events:513 Socket.emit
    node:events:513:28
  
  - readable:324 addChunk
    node:internal/streams/readable:324:12
  
  - readable:297 readableAddChunk
    node:internal/streams/readable:297:9
  
  - readable:234 Socket.Readable.push
    node:internal/streams/readable:234:10
  
  - stream_base_commons:190 TCP.onStreamRead
    node:internal/stream_base_commons:190:23
  

not finished source and transform nodes - 3.339s

error Command failed with exit code 1.

As you can see the asset url http://0.0.0.0:8055/apiassets/fa38e044-7051-478f-bb3e-60a9203cad49 has a missing / after api.

The issue may come come from gatsby-node.js line 91:
const fileUrl = ${plugin.url}assets/${file.id};
There you see the missing /.

Even if add the / to the options.url value in my gatsby-config.ts (like localhost/api/), the trailing slash gets replaced by line 171 in the gatsby-node.js:
const basePath = baseUrl.pathname.endsWith('/') ? baseUrl.pathname.slice(0, -1) : baseUrl.pathname;

Im not sure if im doing anything wrong since im curious about the fact that im the first reporting this.

dependencies

"@directus/gatsby-source-directus": "^9.15.1"
"gatsby": "^5.8.1"
"directus": "^9.20.4"

node v19.9.0

Thanks for your help guys :) greets from germany <3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions