Shopify / shopify-app-js

MIT License
275 stars 108 forks source link

[shopify-app-remix] Cannot read properties of undefined (reading 'headers') #681

Closed koaqiu closed 5 months ago

koaqiu commented 7 months ago

Issue summary

In this tutorial: https://shopify.dev/docs/apps/getting-started/build-qr-code-app?framework=remix

my code

async function supplementQRCode(qrCode:any, graphql:GraphQLClient<any>){
    const qrCodeImagePromise = getQRCodeImage(qrCode.id);

    console.log('qrCode',qrCode);// here can print data
    const response = await graphql(
      `
        query supplementQRCode($id: ID!) {
          product(id: $id) {
            title
            images(first: 1) {
              nodes {
                altText
                url
              }
            }
          }
        }
      `,
      {
        variables: {
          id: qrCode.productId,
        },
      }
    );

  const {
    data: { product },
  } = await response.json();
  return {
    ...qrCode,
    productDeleted: !product?.title,
    productTitle: product?.title,
    productImage: product?.images?.nodes[0]?.url,
    productAlt: product?.images?.nodes[0]?.altText,
    destinationUrl: getDestinationUrl(qrCode),
    image: await qrCodeImagePromise,
  };
}

get error image

03:29:37 │ remix      │ TypeError: Cannot read properties of undefined (reading 'headers')
03:29:37 │ remix      │     at throwFailedRequest (D:\Works\tmp\diy-goods\node_modules\.pnpm\@shopify+shopify-api@9.4.0\
node_modules\@shopify\shopify-api\lib\clients\common.js:52:98)
03:29:37 │ remix      │     at NewGraphqlClient.<anonymous> (D:\Works\tmp\diy-goods\node_modules\.pnpm\@shopify+shopify-
api@9.4.0\node_modules\@shopify\shopify-api\lib\clients\admin\graphql\client.js:70:49)
03:29:37 │ remix      │     at Generator.next (<anonymous>)
03:29:37 │ remix      │     at fulfilled
(D:\Works\tmp\diy-goods\node_modules\.pnpm\tslib@2.6.2\node_modules\tslib\tslib.js:166:62)
03:29:37 │ remix      │     at processTicksAndRejections (node:internal/process/task_queues:95:5)
03:29:37 │ remix      │     at runNextTicks (node:internal/process/task_queues:64:3)
03:29:37 │ remix      │     at process.processImmediate (node:internal/timers:449:9)
03:29:37 │ remix      │ TypeError: Cannot read properties of undefined (reading 'headers')
03:29:37 │ remix      │     at throwFailedRequest (D:\Works\tmp\diy-goods\node_modules\.pnpm\@shopify+shopify-api@9.4.0\
node_modules\@shopify\shopify-api\lib\clients\common.js:52:98)
03:29:37 │ remix      │     at NewGraphqlClient.<anonymous> (D:\Works\tmp\diy-goods\node_modules\.pnpm\@shopify+shopify-
api@9.4.0\node_modules\@shopify\shopify-api\lib\clients\admin\graphql\client.js:70:49)
03:29:37 │ remix      │     at Generator.next (<anonymous>)
03:29:37 │ remix      │     at fulfilled
(D:\Works\tmp\diy-goods\node_modules\.pnpm\tslib@2.6.2\node_modules\tslib\tslib.js:166:62)
03:29:37 │ remix      │     at processTicksAndRejections (node:internal/process/task_queues:95:5)
03:29:37 │ remix      │     at runNextTicks (node:internal/process/task_queues:64:3)
03:29:37 │ remix      │     at process.processImmediate (node:internal/timers:449:9)
03:29:37 │ remix      │ TypeError: Cannot read properties of undefined (reading 'headers')
03:29:37 │ remix      │     at throwFailedRequest (D:\Works\tmp\diy-goods\node_modules\.pnpm\@shopify+shopify-api@9.4.0\
node_modules\@shopify\shopify-api\lib\clients\common.js:52:98)
03:29:37 │ remix      │     at NewGraphqlClient.<anonymous> (D:\Works\tmp\diy-goods\node_modules\.pnpm\@shopify+shopify-
api@9.4.0\node_modules\@shopify\shopify-api\lib\clients\admin\graphql\client.js:70:49)
03:29:37 │ remix      │     at Generator.next (<anonymous>)
03:29:37 │ remix      │     at fulfilled
(D:\Works\tmp\diy-goods\node_modules\.pnpm\tslib@2.6.2\node_modules\tslib\tslib.js:166:62)
03:29:37 │ remix      │     at processTicksAndRejections (node:internal/process/task_queues:95:5)
03:29:37 │ remix      │     at runNextTicks (node:internal/process/task_queues:64:3)
03:29:37 │ remix      │     at process.processImmediate (node:internal/timers:449:9)
03:29:37 │ remix      │ TypeError: Cannot read properties of undefined (reading 'headers')
03:29:37 │ remix      │     at throwFailedRequest (D:\Works\tmp\diy-goods\node_modules\.pnpm\@shopify+shopify-api@9.4.0\
node_modules\@shopify\shopify-api\lib\clients\common.js:52:98)
03:29:37 │ remix      │     at NewGraphqlClient.<anonymous> (D:\Works\tmp\diy-goods\node_modules\.pnpm\@shopify+shopify-
api@9.4.0\node_modules\@shopify\shopify-api\lib\clients\admin\graphql\client.js:70:49)
03:29:37 │ remix      │     at Generator.next (<anonymous>)
03:29:37 │ remix      │     at fulfilled
(D:\Works\tmp\diy-goods\node_modules\.pnpm\tslib@2.6.2\node_modules\tslib\tslib.js:166:62)
03:29:37 │ remix      │     at processTicksAndRejections (node:internal/process/task_queues:95:5)
03:29:37 │ remix      │     at runNextTicks (node:internal/process/task_queues:64:3)
03:29:37 │ remix      │     at process.processImmediate (node:internal/timers:449:9)
paulomarg commented 6 months ago

Hi, thanks for raising this. It seems like there's a bug in the code where we're assuming there will be a response when there is an error, but in this case there isn't one - the real error is masked by this bug, but I'm guessing the request is being aborted somehow.

We'll look into the bug and fix it, but in the meantime I'd suggest checking if the query itself works if you run it in the GraphiQL app from the CLI.

jahilldev commented 6 months ago

I too have recently started to see this. The GraphQL query is working fine 99% of the time, but every now and then, we'll see this error in our logs.

paulomarg commented 5 months ago

I believe this will be fixed by https://github.com/Shopify/shopify-api-js/pull/1330. I'll close this issue but please let us know if it still fails after the next release!

mkromann commented 5 months ago

I was also getting this error but updated to the latest version today. The nature of the error seem to have changed:

2024 04 10_12 33 44 • iTerm — npm run dev-tunnel@2x

Instead getting this message: [shopify-app/DEBUG] Got a response error from the API: Http request error, no response available.

It's hard to replicate the issue, and I am not sure what triggers it.

paulomarg commented 5 months ago

The previous error reported here was actually masking a different issue - the original request got aborted, but we failed to handle that case properly when trying to log this. This error should now be easier to interpret (not really the case here), or at least catchable so you can dig into the data.

With https://github.com/Shopify/shopify-app-js/commit/16f52eef7690260321acd8bfb79f678dd5748fe4, which is coming in the next release, we'll also include some more info in that error message, which will hopefully help us identify the root cause of this issue.

anasdevv commented 6 days ago

@mkromann Were you able to determine what might have been causing the error: Http request error, no response available? I'm getting this same error on graphql client Error: Http request error, no response available: GraphQL Client: request

It’s tricky to replicate the problem on my end, so any insights you have would be really helpful