AppFlow build failing due to a missing optional dependency but local build works ok

Disclaimer: I have always found package dependencies a bit of a mystery!

We have an Angular 13 / Ionic 6 / Capacitor 4 app and we use AppFlow.

Currently the app is building fine locally but on AppFlow the build is failing and I don’t really understand why there is a difference between the two.

The app has a dependency on the ionic-appauth library which has, as an optional dependency, the @awesome-cordova-plugins/secure-storage plugin i.e :

"optionalDependencies": {
    "@awesome-cordova-plugins/secure-storage": "^5.46.0",

The AppFlow error when building is:

Error: node_modules/ionic-appauth/lib/cordova/cordova-secure-storage.d.ts:2:37 - error TS2307: Cannot find module '@awesome-cordova-plugins/secure-storage' or its corresponding type declarations.

2 import { SecureStorageObject } from '@awesome-cordova-plugins/secure-storage';

So if I’m understanding optional dependencies correctly it would appear that when AppFlow runs its npm install this dependency is not being installed, otherwise the build would not fail with the above error.

But locally (and I have the same Node and NPM versions as the AppFlow build stack) if I run npm install and npm build I get no errors.

What would cause this?

Still puzzled by this - does anyone know why the optional dependency is not being installed as party of the AppFlow build?

It appears as though we don’t currently install optional dependencies. Can you try making "@awesome-cordova-plugins/secure-storage an actual dependency?

Yeah, I can get round it this way. I was just a bit surprised that I had to!