Using Capacitor with Nx Monorepo

I have been experimenting with using Capacitor in an Nx monorepo and I am close to getting things working well, but have just a couple of issues. First of all, I would like to have an app in my Nx workspace dedicated to Capacitor for another given app. Directory-wise, it looks like this:


Due to the monorepo nature of Nx, I would like my capacitor.config.json to be located within mobile-app-cap/ so I could have multiple Capacitor apps in a given workspace. The problem is that when I try to do npx cap add from the root of the project then it doesn’t find my capacitor.config.json, and then I run that command from the mobile-app-cap/ folder it says that it cannot find the package.json and should be ran from the root.

That being said, the Ionic CLI has some multi-app support with the ionic.config.json ( so it seems like Capacitor should be able to handle this structure.

Is there a parameter that can be passed into the capacitor commands that can specify the project directory where capacitor.config.json lives and where I want the native project folders to be generated? I ideally would like to run these commands from the root project directory without having to rely on the Ionic CLI.

Thanks in advance!

1 Like

Bringing up old thread as it’s bothering me now:

 % npx cap add ios
[error] The Capacitor CLI needs to run at the root of an npm package.
        Make sure you have a package.json file in the directory where you run the Capacitor CLI.
        More info:

Yes I can work around this by installing @capacitor/cli in my Nx monorepo’s app folder for every app but that’s annoying, it should be at the root of my monorepo instead and be able to cope. This was an unfortunate assumption and should be made more flexible. Thanks!

just install @capcitor/cli with -g flag and npx cap sync will work fine from the project folder without node_module.