gatsby-woocommerce-themes icon indicating copy to clipboard operation
gatsby-woocommerce-themes copied to clipboard

When adding product to cart I get: Cannot read property 'message' of undefined

Open catboxer opened this issue 4 years ago • 6 comments

onError src/components/cart/add-to-cart-button/index.js:63.

  60 |   },
  61 |   onError: (error) => {
  62 |     if (error) {
> 63 |       setRequestError(error.graphQLErrors[0].message);

Installed latest plugins. Any suggestions on what might be the issue would be greatly appreciated.

catboxer avatar Dec 30 '20 06:12 catboxer

I cannot replicate the issue, I deployed and tested here and it works fine. https://gatsby-woocommerce-theme.netlify.app/

Can you console.log( error ) and see what you are getting?

imranhsayed avatar Dec 31 '20 17:12 imranhsayed

when i console.log(error) I get console.log( error ) VM198:1 Uncaught ReferenceError: error is not defined at :1:14

I should have also mentioned that when I clicked add to cart this mutation error came up. I am using the app Local for my local wp development on my site. .env file WORDPRESS_SITE_URL=http://mikestore.local GATSBY_SITE_URL=http://localhost:8000

and when I go to http://localhost:8000/__graphQL it all works.

It is when I click on add to cart that this happens in console:

Uncaught (in promise) TypeError: Cannot read property 'message' of undefined at onError (index.js:63) at MutationData.../node_modules/@apollo/client/react/data/MutationData.js.MutationData.onMutationError (MutationData.js:90) at MutationData.js:22

onError @ index.js:63
  ../node_modules/@apollo/client/react/data/MutationData.js.MutationData.onMutationError @
  (anonymous) @
  Promise.catch (async)  
  MutationData._this.runMutation @
  handleAddToCartClick @
  callCallback @
  invokeGuardedCallbackDev @
  invokeGuardedCallback @
  invokeGuardedCallbackAndCatchFirstError @
  executeDispatch @
  processDispatchQueueItemsInOrder @
  processDispatchQueue @
  dispatchEventsForPlugins @
  (anonymous) @
  batchedEventUpdates$1 @
  batchedEventUpdates @
  dispatchEventForPluginEventSystem @
  attemptToDispatchEvent @
  dispatchEvent @
  unstable_runWithPriority @
  runWithPriority$1 @
  discreteUpdates$1 @
  discreteUpdates @
  dispatchDiscreteEvent

catboxer avatar Dec 31 '20 18:12 catboxer

I am also experiencing this issue. I have a hunch it's relating to a persisting CORS policy issue. Has there been any movement on this? I haven't been able to come to a resolution. @imranhsayed @catboxer

AUFrasier avatar Jan 05 '21 23:01 AUFrasier

I was also experiencing this issue. I resolved the error by changing the GATSBY_WORDPRESS_URL env variable to my WordPress backend url

avidsapp avatar Jan 08 '21 19:01 avidsapp

That worked for me. Thanks

catboxer avatar Jan 12 '21 19:01 catboxer

Screenshot from 2021-10-31 17-56-46 getting this error. Please help. have tried everything i can think of

hofdee avatar Oct 31 '21 15:10 hofdee