Hello,
I’m new to Jira plugin development and I have a very simple issue, that I cannot solve. I couldn’t find any solutions and couldn’t fix it myself.
So, I create a forge app:
? Select a category: UI Kit
? Select a product: Jira
? Select a template: jira-issue-panel
In the backend, I try to get the issue key:
import Resolver from '@forge/resolver';
import api from '@forge/api';
const resolver = async ({ context }) => {
try {
// Get the issue key using the context object
const issueKey = context.issue.key;
// Return the issue key to the frontend
return {
issueKey: issueKey
};
} catch (error) {
console.error('Error retrieving issue key:', error);
return {
error: 'Could not retrieve issue key.'
};
}
};
export const run = resolver;
In the frontend, I try to get it:
import { view, Text, Fragment, useState, useEffect } from '@forge/ui';
import api from '@forge/api';
const App = () => {
const [issueKey, setIssueKey] = useState(null); // Store the issue key
// Fetch the issue key from the backend
useEffect(() => {
const fetchIssueKey = async () => {
try {
const res = await api.asUser().requestJira('/rest/api/3/issue/' + context.issue.key); // Fetch the issue key using Jira API
const data = await res.json();
setIssueKey(data.key); // Set the issue key in the frontend state
} catch (error) {
console.error('Error fetching issue key:', error);
setIssueKey('Error retrieving issue key');
}
};
fetchIssueKey(); // Call the function when the component loads
}, []);
return (
<Fragment>
<Text>The issue key is: {issueKey || 'Loading...'}</Text>
</Fragment>
);
};
export const run = view(App);
I get the error:
Error: Bundling failed: Module not found: Error: Can't resolve 'async_hooks' in '/home/user/source/jira/cbreq/node_modules/@forge/api/out/api', Module not found: Error: Can't resolve 'buffer' in '/home/user/source/jira/cbreq/node_modules/safe-buffer'*
*BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.*
*This is no longer the case. Verify if you need this module and configure a polyfill for it.*
*If you want to include a polyfill, you need to:*
* - add a fallback 'resolve.fallback: { "buffer": require.resolve("buffer/") }'*
* - install 'buffer'*
*If you don't want to include a polyfill, you can use an empty module like this:*
* resolve.fallback: { "buffer": false }
I tried it in so many different ways to get the key, but nothing works. Isn’t there a very basic example that works? I’m doing this since 8 hours and cannot figure it out. Please help.