Hello Developer Community,
Since this afternoon, on only one of my site, my Forge apps fail to load while tunneling with the error:
Uncaught ReferenceError: global is not defined
at getRequestStargate (@forge_api.js?v=2aa81023:26466:26)
at ../../node_modules/@forge/api/out/runtime/fetch-and-storage.js (@forge_api.js?v=2aa81023:26478:39)
at __require (chunk-EWTE5DHJ.js?v=2aa81023:12:50)
at ../../node_modules/@forge/api/out/webTrigger.js (@forge_api.js?v=2aa81023:26490:31)
at __require (chunk-EWTE5DHJ.js?v=2aa81023:12:50)
at ../../node_modules/@forge/api/out/index.js (@forge_api.js?v=2aa81023:26666:24)
at __require (chunk-EWTE5DHJ.js?v=2aa81023:12:50)
at @forge_api.js?v=2aa81023:26785:16
Without tunneling, everything works fine.
I updated @forge/bridge and@forge/resolver to their latest version, I clean the cache of my frontend builder (Vite), I did a force reload of my iframe, of my page … I quit and restart my tunnel … the error is still here.
Does anybody else encounter this error ?
I think we also had this a long time ago and added this to our index.html
<script>
// https://github.com/vitejs/vite/discussions/5912#discussioncomment-5569850
if (global === undefined) {
var global = window;
}
</script>
But TBH I am unsure if this is still needed and fixes tunnel errors…
I’m assuming this is on the frontend (UI Kit or Custom UI)? You might have inadvertently imported @forge/api
in the frontend code - but that package is for the backend (resolver, webtrigger, etc.) code.
I suggest restructuring your code to avoid imports of backend packages in frontend and any shared code, or restricting imports to only types (import type { ... }
).
Yeah likely the same issue as this: Error: There was an error invoking the function - window is not defined - #2 by nathanwaters
@AlexeyKotlyarov can Atlassian please close the loop on these errors.
There are dozens in CDAC that all have the exact same useless error messages in the Forge CLI that are all due to this same problem.
The CLI needs to be updated to show useful error messages. And the Forge bundler needs to do correct tree-shaking because it seems to be including nested imports whether they’re used or not.
All the same cause (search CDAC for these):
window not defined
global not defined
async_hooks
I will try the hack with global = window
, but my main incomprehension is that the same app, same env, same tunnel, but different site works fine 
So for me, something is wrong with the JS loaded on Atlassian/Jira side. I check, and both sites are not part of the Developer Canary Program, but I have the new UI on the broken one, and the current/normal on the working one.
Could others try to open their Forge custom UI with tunnel on site with the new UI ?
Adding in vite.config.ts
:
...
define: {
global: {},
...
}
solved the issue for now.
1 Like