I’m trying to migrate an app from Forge UI 1 to the new UI kit.
I’ve removed any reference to the @forge/ui components and the package.
However, when I run the forge deploy command, I get tons and tons of this error:
TS2304: Cannot find name 'ForgeUI'.[tsl] ERROR in /home/roman/dev/no-more-secrets/src/components/secretsCustomField/secretElements.tsx(34,22)
TS2304: Cannot find name 'ForgeUI'.[tsl] ERROR in /home/roman/dev/no-more-secrets/src/components/secretsCustomField/secretElements.tsx(39,14)
TS2304: Cannot find name 'ForgeUI'.[tsl] ERROR in /home/roman/dev/no-more-secrets/src/components/secretsCustomField/excludedAttachmentMessage.tsx(15,10)
TS2304: Cannot find name 'ForgeUI'.[tsl] ERROR in /home/roman/dev/no-more-secrets/src/components/secretsCustomField/excludedAttachmentMessage.tsx(17,18)
However, there is no reference to ForgeUI in that file.
I’ve no idea what is adding that reference? Seems some configuration doing that?
@RomanStoffel
You get those errors when you import some UI elements from @forge/react into your file which is supposed to live in the backend side of things (resolver).
When you import a file, the file and all its imports are also imported recursively.
You cannot have dependencies to the UI in files for the resolver.
You also cannot have dependencies to the @forge/ui in files for the frontend.
It’s important to break those dependencies by separating clearly those elements in different files.
I ran into a similar issue without any extra imports from @forge/react or elsewhere - just a pure @forge/ui macro configuration. Unfortunately, the only workaround that helped me was:
import ForgeUI, {
MacroConfig,
Option,
Select,
TextArea,
render,
useState,
} from '@forge/ui';
if (false) ForgeUI; // wtf fix for "Cannot find name 'ForgeUI'" issue
You also cannot have dependencies to the @forge/ui in files for the frontend.
Should be
You also cannot have dependencies to the @forge/api in files for the frontend.
Fwiw, for me the cause was that my top-most tsconfig.json had this include: "forge/src/**/*". I guess ESlint/Typescript used too much(?) Forge-code while transpiling and therefore threw those errors.
Fix for me was to push those includes closer to Forge-relevant code. Haven’t fully understand why that works, but the errors disappeared