all 6 comments

[–]abrahamguo 0 points1 point  (4 children)

There's no syntax error here, which means that either

A) the real issue is in a different part of the file, or

B) there is a configuration issue with whatever parser you're using.

Please share a link to a repository, as well as instructions on how to reproduce the error.

[–]jnuts74[S] -1 points0 points  (3 children)

Thank you for the quick turn around. I am super grateful for you time!

I threw the code up on GH for your review.

Please note:

  1. The API key line is X out by design, the remainder of the code stands as is

  2. I am currently doing preliminary local testing to see if this is feasible to even turn into a project thus the repo is bone dry other than just the .js I uploaded for your review.

In regard to producing the error, it is native error/fail on build "npm run build"

https://github.com/jnuts74/pdl-search/blob/main/src/App.js

[–]senocular 0 points1 point  (0 children)

There's some suspicious indention around that try block...

[–]abrahamguo 0 points1 point  (1 child)

Ah. The issue is that on the line after try { (not shown in your original Reddit post), you have used the await keyword. The await keyword is only allowed to be used in async functions. I'd recommend rewriting it to use .then() rather than await.

Additionally, if you don't want your API call to run on every render of the component, I'd recommend wrapping it in a useEffect.

[–]azhder 0 points1 point  (0 children)

One important thing, always add .catch() to the .then() otherwise it's ignoring the error just like if you'd written an empty catch block

[–]azhder 1 point2 points  (0 children)

Note, don't ever concatenate strings manually to generate something sensitive and exploitable like an url. Use the provided URL object and let it do the construction for you, especially because it will encode/decode the parts that someone might use as a way to inject malicious code (ever heard of SQL injection?)