Tchiko
Tchiko

Reputation: 153

Ionic error when try to adding android platform

When i try to add an android platform with this command : ionic cordova platform add android, i got this error :

> ionic cordova resources android --force
> cordova-res.cmd android
[cordova-res] D:\tools\nvm\v14.17.2\node_modules\cordova-res\node_modules\sharp\lib\constructor.js:34
[cordova-res]   throw new Error(error);
[cordova-res]   ^
[cordova-res]
[cordova-res] Error:
[cordova-res] Something went wrong installing the "sharp" module
[cordova-res]
[cordova-res] Cannot find module '../build/Release/sharp.node'
[cordova-res] Require stack:
[cordova-res] - D:\tools\nvm\v14.17.2\node_modules\cordova-res\node_modules\sharp\lib\constructor.js
[cordova-res] - D:\tools\nvm\v14.17.2\node_modules\cordova-res\node_modules\sharp\lib\index.js
[cordova-res] - D:\tools\nvm\v14.17.2\node_modules\cordova-res\dist\image.js
[cordova-res] - D:\tools\nvm\v14.17.2\node_modules\cordova-res\dist\cli.js
[cordova-res] - D:\tools\nvm\v14.17.2\node_modules\cordova-res\dist\index.js
[cordova-res] - D:\tools\nvm\v14.17.2\node_modules\cordova-res\bin\cordova-res
[cordova-res]
[cordova-res] - Run "npm rebuild --verbose sharp" and look for errors
[cordova-res] - Consult the installation documentation at https://sharp.pixelplumbing.com/install
[cordova-res] - Search for this error at https://github.com/lovell/sharp/issues
[cordova-res]
[cordova-res]     at Object.<anonymous> (D:\tools\nvm\v14.17.2\node_modules\cordova-res\node_modules\sharp\lib\constructor.js:34:9)
[cordova-res]     at Module._compile (internal/modules/cjs/loader.js:1085:14)
[cordova-res]     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
[cordova-res]     at Module.load (internal/modules/cjs/loader.js:950:32)
[cordova-res]     at Function.Module._load (internal/modules/cjs/loader.js:790:14)
[cordova-res]     at Module.require (internal/modules/cjs/loader.js:974:19)
[cordova-res]     at require (internal/modules/cjs/helpers.js:92:18)
[cordova-res]     at Object.<anonymous> (D:\tools\nvm\v14.17.2\node_modules\cordova-res\node_modules\sharp\lib\index.js:3:15)
[cordova-res]     at Module._compile (internal/modules/cjs/loader.js:1085:14)
[cordova-res]     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
[ERROR] An error occurred while running subprocess cordova-res.

        cordova-res.cmd android exited with exit code 1.

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

I've installed cordova-res with npm i -g cordova-res but it doesn't resolve the error

Here is my full environment :

Ionic:

   Ionic CLI                     : 6.16.3 (D:\tools\nvm\v14.17.2\node_modules\@ionic\cli)
   Ionic Framework               : @ionic/angular 5.5.2
   @angular-devkit/build-angular : 12.0.1
   @angular-devkit/schematics    : 12.0.5
   @angular/cli                  : 12.0.1
   @ionic/angular-toolkit        : 4.0.0

Cordova:

   Cordova CLI       : 10.0.0
   Cordova Platforms : android 9.1.0
   Cordova Plugins   : no whitelisted plugins (9 plugins total)

Utility:

   cordova-res : not installed globally
   native-run  : not installed globally

System:

   Android SDK Tools : 26.1.1 (C:\tools\android)
   NodeJS            : v14.17.2 (D:\tools\nodejs\node.exe)
   npm               : 6.14.13
   OS                : Windows 10

Environment: #just change here my credential

   HTTP_PROXY       : http://myuser:password@proxyurl:8000
   http_proxy       : http://myuser:password@proxyurl:8000
   HTTPS_PROXY      : http://myuser:password@proxyurl:8000
   https_proxy      : http://myuser:password@proxyurl:8000
   IONIC_HTTP_PROXY : http://myuser:password@proxyurl:8000
   PROXY            : http
   proxy            : http

I don't know if it's related to the node version, if i must downgrade the version It's neccessary to keep all the libs with latest version (ionic and angular)

Upvotes: 2

Views: 1307

Answers (3)

Tchiko
Tchiko

Reputation: 153

After trying to install the different libs such as sharp and cordova-res with matest and previous versions, i'v not resolve the bug

So, i've downgrade the node version to 10.24.1 and i install again directly platform and it works

Upvotes: 0

Danil Prokhorenko
Danil Prokhorenko

Reputation: 1104

In your logs: Something went wrong installing the "sharp" module

So, first of all, you should solve the problem with cordova-res. You can try to install previous versions of cordova-res:

npm install -g [email protected] or below

List of cordova-res versions you can find here: https://www.npmjs.com/package/cordova-res (versions tab)

If this does not help, then you can try to install a globally sharp module (https://www.npmjs.com/package/sharp):

npm install -g sharp

If you will face some problem with cordova-res or sharp installation, please add logs to your question.

Upvotes: 0

Ani
Ani

Reputation: 938

I suggest to uninstall cordova-res and install it again globally

Remove it from your app: npm uninstall cordova-res

Install it globally: npm install -g cordova-res

You are saying that you have run npm i -g cordova-res, but in your full environment:

Utility:
cordova-res : not installed globally

Upvotes: 2

Related Questions