Error while setting issue properties (syntax issue)

I am attempting to set an issue property following the information here. I’m placing the code in the App() function in my index.jsx, which is linked to an issue panel.

Here is the code:

const App = () => {	
  const context = useProductContext();  
  await properties.onJiraIssue(context.platformContext.issueKey).set('my-key', 'hello-world');

I get this error message in the console:

Error: Bundling failed: ./src/index.jsx
Module build failed (from /tunnel/node_modules/babel-loader/lib/index.js):
SyntaxError: /app/src/index.jsx: 'await' is only allowed within async functions. (45:2)

I know that I need to wrap the command in an async function in some way, but I’m not sure what the best way to do that is. Thankyou!

Hi @craig.schwarze

Thanks for reaching out.

I believe this error is due to including the await directly in your App function rather than put it inside a useState callback, such as:

const myasyncmethod = async (input) => {
  // do some delayed stuff
  await Promise.resolve('value');

const App = () => {
  const context = useProductContext();

  const [data] = useState(async () => await myasyncmethod(context));
  console.log(data); // should now log 'value'

Hope this helps :slight_smile:


Thankyou! I will try this out