-
Type:
Suggestion
-
Resolution: Unresolved
-
Component/s: Forge - App Code Execution
-
None
The bundler doesn’t appear to properly remove unused code.
For example…
helpers.jsx (utility helpers)
import
Unknown macro: {storage}from @forge/api
export const foo = () =>
Unknown macro: { // this helper function only used in frontend return "hello" }
export const bar = () =>
Unknown macro: { // this helper function only used in backend return storage.get('thing') }
index.jsx (frontend)
import * as Helpers from './helpers'
const App = () =>
Unknown macro: { Helpers.foo() }
resolver.js (backend)
import * as Helpers from './helpers'
resolver.define('do', (req)) =>
Unknown macro: { Helpers.bar() })
What the Forge bundler should do is recognise that @forge/api here is only being used in the backend resolver. But instead it seems to bundle everything and thus throws an error because it assumes you’re trying to also use that package in the frontend. I think this explains most of the CDAC posts regarding the non-descriptive errors.