Error: Cannot read property 'replace' of undefined

hello there, I am getting the same error on mac with CLI 3.4.
do you mind to share what are the things that you reinstalled?

1 Like

What command exactly are you running?
What error are you getting?
What is your ionic info output?

ionic cordova run ios

** BUILD SUCCEEDED **

Error: Cannot read property ā€˜replaceā€™ of undefined

[ERROR] Cordova encountered an error.
You may get more insight by running the Cordova command above directly.

[ERROR] An error occurred while running cordova run ios (exit code 1).

global packages:

@ionic/cli-plugin-proxy : 1.3.1
@ionic/cli-plugin-proxy : 1.3.1
@ionic/cli-utils        : 1.4.0
Cordova CLI             : 7.0.1
Ionic CLI               : 3.4.0

local packages:

@ionic/app-scripts              : 1.3.7
@ionic/cli-plugin-cordova       : 1.4.0
@ionic/cli-plugin-ionic-angular : 1.3.1
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 : not installed
ios-sim    : not installed
npm        : 3.10.10

I tried to remove platform and add again but still getting same error

1 Like

Yeah, different error - I moved your post to its own topic.

Run ionic cordova run ios --verbose please.

1 Like

Hi, thanks for moving my post.

Here is the outcome when I run ionic cordova run ios --verbose

Signing Identity: ā€œ-ā€

/usr/bin/codesign --force --sign - --timestamp=none /Users/menghao/Documents/development/project/platforms/ios/build/emulator/ubahapp.app

** BUILD SUCCEEDED **

Error: Cannot read property ā€˜replaceā€™ of undefined

[ERROR] Cordova encountered an error.
You may get more insight by running the Cordova command above directly.

[DEBUG] !!! ERROR ENCOUNTERED !!!
[ERROR] An error occurred while running cordova run ios (exit code 1).

Thanks

Please edit your post and use the </> button above the post input field to format your code or error message or wrap it in ``` (ā€œcode fencesā€) manually. This will make sure your text is readable and if it recognizes the programming language it also automatically adds code syntax highlighting. Thanks.

Also we need the whole output kinda, not just the end.

Hi,
i think this is the same error as here:

This is the offical bug fix from Cordova:
in your project folder root, do cd platforms/ios/cordova && npm install ios-sim

Regards
Stefan

10 Likes

Ran into the same issue, when I opened Xcode I received a notifications about needing to install additional components. After installing the updates, I was able to run the Ionic project again.

Update

Actually, I was mistaken, looks like it was @Sujan12 suggest on "Error: Cannot read property ā€˜replaceā€™ of undefined" for ios-sim that actually fixed the issue for me.

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

Still get this error targeting specific devices even after installing ios-sim locally.

1 Like

Confirming that installing ios-sim solved my issue too.

1 Like

This also worked for me, many thanks @stefan610!

1 Like

Here I had the same error ā€œError: Cannot read property ā€˜replaceā€™ of undefinedā€ and it was solved when by opening the Android Studio and creating a new avd.

1 Like

This issue is fixed in the latest version of the ā€œios-simā€ package (so now this is probably the easier solution - compared to the old one which is listed below). In order to update the ā€œios-simā€ package to the latest version run this in your terminal/cmd:

cd platforms/ios/cordova/node_modules/
sudo npm install ios-sim@latest
7 Likes

Thank you very much, it work!!!

1 Like

cd platforms/ios/cordova/node_modules/
sudo npm install ios-sim@latest

This worked for me, thanks @Ahmed12 !

2 Likes

thanks, worked like a charm!

1 Like

Thanks, Ionic Team should somehow fix this issue.

1 Like

This worked for me! Thanks.

Worked like a charm. Thank you @dalezak

Those interested in automating this (@diljitvj), you could add the following hook:

/hooks/after_platform_add/010_install_sim.js
#!/usr/bin/env node

var fs = require('fs');
var path = require('path');
var exec = require('child_process').exec;
var root = process.argv[2];
var platform = process.env.CORDOVA_PLATFORMS;

function puts(error, stdout, stderr) {
  console.log(stdout);
}

function installCordovaIosSim() {
  exec("cd platforms/ios/cordova && npm install ios-sim", puts)
}

if (platform === 'ios') {
  installCordovaIosSim();
}

Now upon adding the iOS platform to your Ionic project, this command will automatically get executed :+1: