Struggling with getAppContext (Forge runtime not found)

Hi,

I try to use getAppContext to get the installed version of the App, but I can’t make it work with the example of the doc https://developer.atlassian.com/platform/forge/runtime-reference/app-context-api/

import { getAppContext } from "@forge/api";

const { appAri, appVersion, environmentAri, environmentType, invocationId, installationAri, moduleKey } = getAppContext();

console.log(appAri.toString());

The error text is:

Uncaught (in promise) Error: Forge runtime not found.
    at n (runtime.js:10:15)
    at r.getAppContext (runtime.js:16:108)
    at settings.js:2:3574

Any idea? Or someone who has already tested it and could confirm that it works?
Thanks for your help :slight_smile:

Hi @BertrandDrouhard1

Can you confirm you are using the preview native Node runtime?

Your app should have the following in the manifest:

app:
  runtime:
    name: nodejs18.x

Thanks

1 Like

Hi Sam, yes I use the native Node.JS.

If you can share your appId either here or over direct message I can take a look into this for you.

2 Likes

I tried with and without tunneling, same issue. Inside App() or before, same problem.

So I have just tested it in a blank App (hello-world-app from https://developer.atlassian.com/platform/forge/build-a-hello-world-app-in-jira/ ), deployed in development environment, to make sure that it does not depend on my existing project or my computer. But I still have the same error message.

import React, { useEffect, useState } from 'react';
import ForgeReconciler, { Text } from '@forge/react';
import { invoke } from '@forge/bridge';

// Added for getAppContext testing
import { getAppContext } from "@forge/api";
const { appAri, appVersion, environmentAri, environmentType, invocationId, installationAri, moduleKey } = getAppContext();
console.log(appAri.toString());
// End of Added for getAppContext testing

const App = () => {
  const [data, setData] = useState(null);
  useEffect(() => {
    invoke('getText', { example: 'my-invoke-variable' }).then(setData);
  }, []);
  return (
    <>
      <Text>Hello world!</Text>
      <Text>{data ? data : 'Loading...'}</Text>
    </>
  );
};

ForgeReconciler.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);

It looks like a bug on the Forge side.

You are using a backend function on the frontend; therefore, yes, the runtime is not found.

import { getAppContext } from "@forge/api";

Can only be used in a resolver function.

3 Likes

Thank you Silvère, it’s working now! No bug from Atlassian (shame on me :grinning: !)