cordovaionic-frameworkionic3android-buildionic-cli

Ionic fails to build or run the application


I'm trying to build my ionic app, but it fails with below error. The error is same with ionic run android command too. The app runs with no error with ionic serve command. I have even tried with ionic cordova build ios and the error remains same.

Error:

npm run ionic:build:before
Pay@0.0.1 ionic:build:before d:\PsResources\DroidWorkspace\Pay\Pay
node ./src/bin/script.js

module.js:550
    throw err;
    ^

Error: Cannot find module 
'd:\PsResources\DroidWorkspace\Pay\Pay\src\bin\script.js'
    at Function.Module._resolveFilename (module.js:548:15)
    at Function.Module._load (module.js:475:25)
    at Function.Module.runMain (module.js:694:10)
    at startup (bootstrap_node.js:204:16)
    at bootstrap_node.js:625:3
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! Pay@0.0.1 ionic:build:before: `node ./src/bin/script.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the Pay@0.0.1 ionic:build:before script.
npm ERR! This is probably not a problem with npm. There is likely additional 
logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Suroor\AppData\Roaming\npm-cache\_logs\2018-10-30T17_30_14_997Z-debug.log
[ERROR] An error occurred while running subprocess npm.

    npm run ionic:build:before exited with exit code 1.
Re-running this command with the --verbose flag may provide more information.

Ionic Info:

Ionic:
   ionic (Ionic CLI)  : 4.2.1 (C:\Users\Suroor\AppData\Roaming\npm\node_modules\ionic)
   Ionic Framework    : ionic-angular 3.9.2
   @ionic/app-scripts : 3.2.0

Cordova:
    cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1)
    Cordova Platforms     : android 7.1.1, browser 4.1.0, ios 4.3.1
    Cordova Plugins       : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 2.2.0, (and 5 other plugins)

System:

 (D:\Software\~ProgrammingTools\SDK)
   NodeJS            : v8.12.0 (C:\Program Files\nodejs\node.exe)
   npm               : 6.4.1
   OS                : Windows 7

Solutions Tried:

  1. Deleted node_modules and installed again.
  2. Removed and installed latest version of cordova and ionic-app-scripts.
  3. Downgraded cordova to 4.2.0.
  4. All env variables are proper.

Update: Its trying to access script.js file from d:\PsResources\DroidWorkspace\Pay\Pay\src\bin\script.js which is not even exist.


Solution

  • Found a solution for this (May not be appropriate), I removed

    "ionic:watch:before": "node ./src/bin/script.js",
    "ionic:build:before": "node ./src/bin/script.js"
    

    from package.json scripts, and now it builds successfully. I don't know what is the purpose of above scripts, but it works for now, and generated Apk works fine in the device.