Ionic无法生成或运行应用程序

时间:2018-10-30 17:42:46

标签: cordova ionic-framework ionic3 android-build ionic-cli

我正在尝试构建我的离子应用程序,但由于出现以下错误而失败。该错误也与ionic run android命令相同。使用ionic serve命令,该应用程序运行无错误。我什至尝试使用ionic cordova build ios,但错误仍然相同。

错误:

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:
   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

尝试过的解决方案:

  1. 删除了node_modules并重新安装。
  2. 删除并安装了最新版本的cordova和ionic-app-scripts。
  3. 将cordova降级为4.2.0。
  4. 所有env变量都是正确的。

更新: 它试图从甚至不存在的script.js访问d:\PsResources\DroidWorkspace\Pay\Pay\src\bin\script.js文件。

1 个答案:

答案 0 :(得分:0)

为此找到了解决方案(可能不合适),我删除了

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

package.json脚本开始,现在可以成功构建。我不知道上述脚本的目的是什么,但是它现在可以正常工作,并且生成的Apk在设备中可以正常工作。