"Error: Cannot read property ‘replace’ of undefined" for ios-sim

I have the same problem…

ionic emulate ios

…gives…

** BUILD SUCCEEDED **
Error: Cannot read property ‘replace’ of undefined

This guy seem to have found the bug: https://stackoverflow.com/questions/42350505/error-cannot-read-property-replace-of-undefined-when-building-ios-cordova

I would like to know how to solve it.

My system:

Cordova CLI: 7.0.1
Ionic Framework Version: 3.1.1
Ionic CLI Version: 2.2.3
Ionic App Lib Version: 2.2.1
Ionic App Scripts Version: 1.3.4
ios-deploy version: 1.9.0
ios-sim version: 5.0.8
OS: macOS Sierra
Node Version: v6.10.1
Xcode version: Xcode 8.3.3 Build version 8E3004b

looks like a new issues that just hit…getting the same thing…

global packages:

@ionic/cli-utils : 1.3.0
Cordova CLI      : 6.5.0 
Ionic CLI        : 3.3.0

local packages:

@ionic/app-scripts              : 1.3.7
@ionic/cli-plugin-cordova       : 1.3.0
@ionic/cli-plugin-ionic-angular : 1.3.0
Cordova Platforms               : android 6.2.3 ios 4.3.1
Ionic Framework                 : ionic-angular 3.3.0

System:

Node       : v7.2.1
OS         : macOS Sierra
Xcode      : Xcode 8.3.3 Build version 8E3004b 
ios-deploy : 1.9.1 
ios-sim    : 3.1.1

Just started affecting me last night after updating Xcode, can’t test via ionic run --device (ios device) or ionic emulate ios

Broke since updating to Xcode 8.3.3 for me as well.

same here…time to roll Xcode back…

https://developer.apple.com/download/more/

update: this didn’t help…nor did removing and adding the platform…

1 Like

I don’t think the SO answer can be relevant to OP’s situation, because OP is trying to run an android emulator, not an iOS one, so I would not think ios-sim would come into play.

Can everybody affected please post the following details:

  • exactly what command you were running
  • the stacktrace of the build failure

ahh I already rolled back and deleted the new Xcode, but I can say that rolling back did indeed work.

Getting the same issue:

global packages:

    @ionic/cli-utils : 1.3.0
    Cordova CLI      : 7.0.1
    Ionic CLI        : 3.3.0

local packages:

    @ionic/app-scripts              : 1.3.7
    @ionic/cli-plugin-cordova       : 1.3.0
    @ionic/cli-plugin-ionic-angular : 1.3.0
    Cordova Platforms               : ios 4.4.0
    Ionic Framework                 : ionic-angular 3.3.0

System:

    Node       : v6.10.3
    OS         : macOS Sierra
    Xcode      : Xcode 8.3.3 Build version 8E3004b
    ios-deploy : 1.9.1
    ios-sim    : 5.0.13

how did you roll back? I rolled back to 8.3.2 and still have the issue…

I downloaded it from your link and then trashed the newest version. If I remember correct I had the issue until I trashed the newest version.
Edit: But I also did created a new project since I am now migrating to v2 and I also update my cli to v3. So I don’t know if my previous v1 app would work.

Anybody who is still having this problem:

  1. Run the ionic cordova command with --verbose at the end and post the command and its result.
  2. Run the command without the ionic in the beginning, so it is a cordova command and post the command and its result.
  3. Post your ionic info output with the two other outputs for context.

Thanks.

#1 - didn’t return anything useful
#2-

cordova run iOS --verbose
...
** BUILD SUCCEEDED **

No scripts found for hook "before_deploy".
Error: TypeError: Cannot read property 'replace' of undefined
    at remove (/Users/BCH/mobilebusinessapp/platforms/ios/cordova/node_modules/ios-sim/src/lib.js:282:70)
    at Array.forEach (native)
    at Object.getdevicetypes (/Users/BCH/mobilebusinessapp/platforms/ios/cordova/node_modules/ios-sim/src/lib.js:292:22)
    at Object.listEmulatorImages [as run] (/Users/BCH/mobilebusinessapp/platforms/ios/cordova/lib/list-emulator-images:34:29)
    at deployToSim (/Users/BCH/mobilebusinessapp/platforms/ios/cordova/lib/run.js:146:50)
    at /Users/BCH/mobilebusinessapp/platforms/ios/cordova/lib/run.js:88:20
    at _fulfilled (/Users/BCH/mobilebusinessapp/platforms/ios/cordova/node_modules/q/q.js:834:54)
    at self.promiseDispatch.done (/Users/BCH/mobilebusinessapp/platforms/ios/cordova/node_modules/q/q.js:863:30)
    at Promise.promise.promiseDispatch (/Users/BCH/mobilebusinessapp/platforms/ios/cordova/node_modules/q/q.js:796:13)
    at /Users/BCH/mobilebusinessapp/platforms/ios/cordova/node_modules/q/q.js:604:44

#3 - ionic info:
global packages:

@ionic/cli-utils : 1.3.0
Cordova CLI      : 6.5.0 
Ionic CLI        : 3.3.0

local packages:

@ionic/app-scripts              : 1.3.7
@ionic/cli-plugin-cordova       : 1.3.0
@ionic/cli-plugin-ionic-angular : 1.3.0
Cordova Platforms               : android 6.2.3 ios 4.3.1
Ionic Framework                 : ionic-angular 3.3.0

System:

Node       : v7.2.1
OS         : macOS Sierra
Xcode      : Xcode 8.3.2 Build version 8E2002 
ios-deploy : 1.9.1 
ios-sim    : 3.1.1

yeah I installed 8.3.2 and dragged it to the applications folder so it replaced 8.3.3 I never manually deleted the 8.3.3 install.

Ok, here it is quite clear: Your [quote=“BradH, post:14, topic:93297”]
ios-sim : 3.1.1
[/quote]
version is ancient. Find out if it is installed locally or globally and then run npm install -g ios-sim or npm install ios-sim. (I suspect globally). Run ionic info to check again if the update worked.

yeah it was old, if it aint broke don’t fix it, has been my approach on ionic as the more you update the more that breaks…

updated it to the current 5.1.0 but I still get the same issue…

ios-sim is part of Cordova, not Ionic directly. And obviously it is broken if you are getting errors :wink:
There is an issue here, but I am not sure if the solution is the correct one for you: https://github.com/phonegap/ios-sim/issues/210

What did you mean by that by the way? Nothing additional?

Another idea from here: https://github.com/phonegap/ios-sim/issues/210

Check if you have a local ios-sim maybe that could clash with the global one. (Look into node_modules folder)

Worked Great Thanks!

I removed the ios-sim directory inside myApp/platforms/ios/cordova/node_modules and now it’s working. Now it uses the global installed one i guess. Thanks! :slight_smile:

3 Likes

Do you remember or can check when (and why) ios-sim got added locally (maybe via package.json blame in git)?

Update: Just realized that it’s in /platforms/ios/cordova/ - and there is no package.json there.
Update 2: Got it: https://github.com/apache/cordova-ios/blob/master/package.json#L49

So here is the “official” fix from someone Cordova team:

in your project folder root, do cd platforms/ios/cordova && npm install ios-sim

https://github.com/phonegap/ios-sim/issues/210#issuecomment-307465853

(Which also means: You can/should get rid of the global install via npm uninstall -g ios-sim)

17 Likes