¿How can i add an npm install –force when i execute ionic build android?

Issue

I execute this command

ionic capacitor sync android

But i had this conflictive modules ->

C:\Users\DELL\Documents\inspecciones\inpecciones-app>ionic capacitor sync android
> npm.cmd i -E @capacitor/[email protected]
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: @angular-devkit/[email protected]
npm ERR! Found: @angular/[email protected]
npm ERR! node_modules/@angular/compiler-cli
npm ERR!   dev @angular/compiler-cli@"~12.0.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/compiler-cli@"^15.0.0" from @angular-devkit/[email protected]
npm ERR! node_modules/@angular-devkit/build-angular
npm ERR!   dev @angular-devkit/build-angular@"^15.1.5" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: @angular/[email protected]
npm ERR! node_modules/@angular/compiler-cli
npm ERR!   peer @angular/compiler-cli@"^15.0.0" from @angular-devkit/[email protected]
npm ERR!   node_modules/@angular-devkit/build-angular
npm ERR!     dev @angular-devkit/build-angular@"^15.1.5" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See C:\Users\DELL\AppData\Local\npm-cache\eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\DELL\AppData\Local\npm-cache\_logs\2023-02-14T21_22_36_075Z-debug-0.log
[ERROR] An error occurred while running subprocess npm.

        npm.cmd i -E @capacitor/[email protected] exited with exit code 1.

        Re-running this command with the --verbose flag may provide more information.

So when it runs -> execute an npm i but i want to add an --force

Solution

In your package.json you can define custom scripts that can run multiple commands after each other.

Below is an Implementation that

  1. installs npm Packages with -force flag
  2. builds your ionic project
  3. syncs your ionic build with your android build
  4. opens android studio with your android project

To implement add this to your package.json:

"scripts":
{
    "android": "npm i -force && ionic build && ionic capacitor sync android && ionic capacitor open android"
}

The script can be called with

npm run %script name%

So in this case:

npm run android

Answered By – Greencoms

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published