Npm run build fails when importing @forge/api


I decided to test to build a JIRA App with Forge. Now I am stuck when trying to import @forge/api to use api component. I am using the AdminPage Custom UI template. When I followed this guide with UI Kit template everything worked fine:

The problem I have is on this file: Forge-App-Adminpage/Table.js at main · Davvee/Forge-App-Adminpage · GitHub

When I import @forge/api and trying to build it (npm run build) I get this error message:
Creating an optimized production build…
Failed to compile.

Module not found: Error: Can’t resolve ‘url’ in ‘C:\Users\David\Documents\forge-app-adminpage\static\hello-world\node_modules@forge\egress\out\egress’
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: { “url”: require.resolve(“url/”) }’
- install ‘url’
If you don’t want to include a polyfill, you can use an empty module like this:
resolve.fallback: { “url”: false }

I am running on Node JS v18.13.0.

If I remove the @forge/api import and the referred code the build is working ok again.

EDIT: I can also mentioned that the error disappears if I change this line
“target: [‘browserslist’],”
“target: ‘node’,”
in webpack.config.js file. But I am not sure if that is the correct way to handle this since I get some other strange problems when the code is deployed like missing referrences on “global” and “require”. Not sure if it is related though.

Hello David,

@forge/api package can only be used in the Forge backend (which includes UI Kit, since the UI is defined while running the backend code). That’s why it requires node in the config, and references Node.js APIs such as url, global and require.

To call Jira from Custom UI, use @forge/bridge instead.

Hi Alexey!

Ah, I’ll try that instead. Thanks for your support.

1 Like