Why do I have to manually install api with npm install @forge/api?

Shouldn’t this be automatically installed using npm install if I’m referencing api in my code? It seems like I have to install this manually everytime or I get the ‘route not defined’ error in my app.

@EricKruegerStrataCom,

Can you elaborate on “install this manually everytime”? Do you mean every time you start a new Forge App? Or every deploy? Or…?

Every time I start a new forge app, if I have an api call in there and need to import route, I’ll get errors on deploy unless I manually install the forge api packages. I only have to install the one time, but it’s one time per app. So each new app I need to install. I though npm install at the root should take care of this, but it doesn’t work for me.

@EricKruegerStrataCom,

Thanks for explaining. I can confirm that’s typical Node.js behavior. The dependencies for every project must be explicit in the package.json. Hence, the packages must be installed for every app.

I’m not sure what you mean by “installed at the root” but that sounds like it’s outside of the scope governed by a local, project-level package.json. Maybe with npm -g?

If you have a lot of similarities between apps, you might invest in a “monorepo” approach which helps with some degree of dependency sharing. To my knowledge, the idea of “workspaces” inside a larger “monorepo” began with yarn but I think the “cool kids” use tools like Nx or turbo.

That said, please don’t consider that a recommended solution (neither from Atlassian nor personally). There is an incredible trade-off for increased complexity, and without really removing the need for managing lots of fiddly package.json details. I find myself creating a new Forge app every other week or so, and I just find it more convenient to copy my last project’s project.json along with many of the settings files (linting, formatting, etc) and pare down the manifest.yml and dependencies, than to use a template and build up again.