imranhsayed / gatsby-woocommerce-themes

⚡ A Gatsby Theme for WooCommerce E-commerce site Gatsby WooCommerce WordPress
https://gatsby-woocommerce-theme.netlify.app/
MIT License
606 stars 308 forks source link

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

Open catboxer opened 3 years ago

catboxer commented 3 years ago

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.

imranhsayed commented 3 years ago

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?

catboxer commented 3 years ago

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 @ MutationData.js:90
  (anonymous) @ MutationData.js:22
  Promise.catch (async)    
  MutationData._this.runMutation @ MutationData.js:21
  handleAddToCartClick @ index.js:70
  callCallback @ react-dom.development.js:3946
  invokeGuardedCallbackDev @ react-dom.development.js:3995
  invokeGuardedCallback @ react-dom.development.js:4057
  invokeGuardedCallbackAndCatchFirstError @ react-dom.development.js:4071
  executeDispatch @ react-dom.development.js:8244
  processDispatchQueueItemsInOrder @ react-dom.development.js:8276
  processDispatchQueue @ react-dom.development.js:8289
  dispatchEventsForPlugins @ react-dom.development.js:8300
  (anonymous) @ react-dom.development.js:8509
  batchedEventUpdates$1 @ react-dom.development.js:22397
  batchedEventUpdates @ react-dom.development.js:3746
  dispatchEventForPluginEventSystem @ react-dom.development.js:8508
  attemptToDispatchEvent @ react-dom.development.js:6006
  dispatchEvent @ react-dom.development.js:5925
  unstable_runWithPriority @ scheduler.development.js:646
  runWithPriority$1 @ react-dom.development.js:11277
  discreteUpdates$1 @ react-dom.development.js:22414
  discreteUpdates @ react-dom.development.js:3757
  dispatchDiscreteEvent
AUFrasier commented 3 years ago

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

avidsapp commented 3 years ago

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

catboxer commented 3 years ago

That worked for me. Thanks

hofdee commented 3 years ago

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