Question regarding @forge/api with webpack

Hi,

Thanks for the attention. So, currently, I’m developing an app for hackathon event posted in devpost (specifically, the one hosted in here)

And, I’m having a difficulty trying to run these code

import api, { route } from '@forge/api';

const findProjects = async () => {
  const user = api.asUser();
  const endpoint = route('/rest/api/2/project');

  const response = await user.requestJira(endpoint);

  console.log(response); 
};

(async () => {
  await findProjects();
})().then(() => console.log('done')); 

in my local, the code will throw an error

TypeError: proxy is undefined
  createProxyFetch webpack://atlassian-dev-unleashed/./node_modules/@forge/api/out/api/fetch.js?:17
  wrapRequestProduct webpack://atlassian-dev-unleashed/./node_modules/@forge/api/out/api/index.js?:22 

So, I’m just wondering, is the issue caused by using webpack? If that’s the case, is there any workaround for this issue? there should be something I missed in here, so any feedback is definitely appreciated.

Thanks and have a nice day.

Regards,
Ivan

If you’re trying to run the above in the browser - then that won’t work. @forge/api is reserved to be run in the Forge functions. For the Custom UI - you need the @forge/bridge module - https://developer.atlassian.com/platform/forge/custom-ui-bridge/bridge/

3 Likes

Hi Daniel,

Thanks for the answer, I didn’t aware about that. Currently, I’m still changing my code. If that’s fixed the issue. I will mark your answer as the solution.

Thanks again. and have a nice day.

Regards,
Ivan