Error: Cannot read property 'replace' of undefined


#1

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?


Run/Build always "fails" with "exit code 1" even on success
#2

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


#3

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


#4

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

Run ionic cordova run ios --verbose please.


#5

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


#6

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.


#7

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


#8

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

#9

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


#10

Confirming that installing ios-sim solved my issue too.


#11

This also worked for me, many thanks @stefan610!


#12

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.


#13

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

#14

Thank you very much, it work!!!


#15

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

This worked for me, thanks @Ahmed12 !


#16

thanks, worked like a charm!


#17

Thanks, Ionic Team should somehow fix this issue.


#18

This worked for me! Thanks.


#19

Worked like a charm. Thank you @dalezak


#20

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: