Ionic Build failing (v2)
Ionic version: (check one with "x") [ ] 1.x [ x] 2.x
ionic build ios isn't working at all for me. ionic serve works fine but whenever I try to build I get the error below. In my package.json I have appended --dev to the build script command because every time I build it builds production which takes forever, and this little bypass has been working for weeks until tonight.
I can't seem to find any problems in my code and serve works fine.
> ionic-hello-world@ ionic:build
> ionic-app-scripts build --dev
[00:06:04] ionic-app-scripts 0.0.45
[00:06:04] build dev started ...
[00:06:04] clean started ...
[00:06:04] clean finished in 4 ms
[00:06:04] copy started ...
[00:06:04] transpile started ...
[00:06:07] build dev failed: Cannot read property 'indexOf' of undefined
[00:06:07] ionic-app-script task: "build"
[00:06:07] TypeError: Cannot read property 'indexOf' of undefined
npm ERR! Darwin 16.0.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "ionic:build" "--"
npm ERR! node v6.9.2
npm ERR! npm v3.10.9
npm ERR! code ELIFECYCLE
npm ERR! ionic-hello-world@ ionic:build: `ionic-app-scripts build --dev`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ionic-hello-world@ ionic:build script 'ionic-app-scripts build --dev'.
Cordova CLI: 6.4.0
Ionic Framework Version: 2.0.0-rc.3-201611302233
Ionic CLI Version: 2.1.17
Ionic App Lib Version: 2.1.7
Ionic App Scripts Version: 0.0.45
ios-deploy version: 1.9.0
ios-sim version: 5.0.6
OS: macOS Sierra
Node Version: v6.9.2
Xcode version: Xcode 8.1 Build version 8B62
Hello @Tyler-Darby thats because build is running ngc checks, serve not.
It looks like a variable is undefined/null where you're trying to do an indexof
I've already asked a same question, look here: #9045
So what shall you do?
Look in your code where you use indexof and check if the variable is intialized first.
Don't:
test:Array<any>
Do:
test:Array<any>=[];
Greetings Graphefruit
@graphefruit I've searched over my whole src directory using my IDE and I don't use indexOf in my code once. The only place it is used is service-worker.js
Could this be caused by a NPM package? I am using AngularFire2 with firebase currently and the problems seem to have started around that time, could that be the case?
Do you have an import * as firebase from 'firebase'? If AngularFire2 is setup correctly, you don't need this import anymore.
@urm47 Nope. Got rid of all of those. Pretty stumped here, completely removed angularfire from my project and the issue still persists. It gives me no line numbers, no stack trace, nothing. Not even the npm-debug.log Here it is if it's any assistance.
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node',
1 verbose cli '/usr/local/bin/npm',
1 verbose cli 'run',
1 verbose cli 'ionic:build',
1 verbose cli '--' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'preionic:build', 'ionic:build', 'postionic:build' ]
5 info lifecycle ionic-hello-world@~preionic:build: ionic-hello-world@
6 silly lifecycle ionic-hello-world@~preionic:build: no script for preionic:build, continuing
7 info lifecycle ionic-hello-world@~ionic:build: ionic-hello-world@
8 verbose lifecycle ionic-hello-world@~ionic:build: unsafe-perm in lifecycle true
9 verbose lifecycle ionic-hello-world@~ionic:build: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:(redacted project dir)/node_modules/.bin:(redacted dir).rvm/gems/ruby-2.3.1/bin:(redacted dir).rvm/gems/ruby-2.3.1@global/bin:(redacted dir).rvm/rubies/ruby-2.3.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/MacGPG2/bin:(redacted project dir)/.rvm/bin
10 verbose lifecycle ionic-hello-world@~ionic:build: CWD: (redacted project dir)
11 silly lifecycle ionic-hello-world@~ionic:build: Args: [ '-c', 'ionic-app-scripts build --dev' ]
12 silly lifecycle ionic-hello-world@~ionic:build: Returned: code: 1 signal: null
13 info lifecycle ionic-hello-world@~ionic:build: Failed to exec ionic:build script
14 verbose stack Error: ionic-hello-world@ ionic:build: `ionic-app-scripts build --dev`
14 verbose stack Exit status 1
14 verbose stack at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:255:16)
14 verbose stack at emitTwo (events.js:106:13)
14 verbose stack at EventEmitter.emit (events.js:191:7)
14 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:40:14)
14 verbose stack at emitTwo (events.js:106:13)
14 verbose stack at ChildProcess.emit (events.js:191:7)
14 verbose stack at maybeClose (internal/child_process.js:877:16)
14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
15 verbose pkgid ionic-hello-world@
16 verbose cwd (redacted dir)
17 error Darwin 16.0.0
18 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "ionic:build" "--"
19 error node v6.9.2
20 error npm v3.10.9
21 error code ELIFECYCLE
22 error ionic-hello-world@ ionic:build: `ionic-app-scripts build --dev`
22 error Exit status 1
23 error Failed at the ionic-hello-world@ ionic:build script 'ionic-app-scripts build --dev'.
23 error Make sure you have the latest version of node.js and npm installed.
23 error If you do, this is most likely a problem with the ionic-hello-world package,
23 error not with npm itself.
23 error Tell the author that this fails on your system:
23 error ionic-app-scripts build --dev
23 error You can get information on how to open an issue for this project with:
23 error npm bugs ionic-hello-world
23 error Or if that isn't available, you can get their info via:
23 error npm owner ls ionic-hello-world
23 error There is likely additional logging output above.
24 verbose exit [ 1, true ]
Also I should add that production builds build fine.
This issue was moved to driftyco/ionic-app-scripts#530
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.