Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
catboxer opened this issue Dec 30, 2020 · 6 comments

Comments

@catboxer
Copy link

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
Copy link
Owner

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
Copy link
Author

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

@AUFrasier
Copy link

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
Copy link

avidsapp commented Jan 8, 2021

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

@catboxer
Copy link
Author

That worked for me. Thanks

@hofdee
Copy link

hofdee commented Oct 31, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants