Error: Cannot read the "replace" property from undefined when creating iOS Cordova

I created a cordova project using cordova create project hello com.hello Hello .

And the iOS platform was added using the cordova platform add iOS . And tried to make cordova run ios after cordova build ios .

But this shows me this error (I used --d / - verbose to get the details).

/ usr / bin / codesign --force --sign - --timestamp = none /Volumes/Untitled/Plot/PlotReel/platforms/ios/build/emulator/PlotReel.app / Volumes / Untitled / Plot / PlotReel / platforms / ios /build/emulator/PlotReel.app: replacing an existing signature

** BUILD SUCCEEDED **

No scripts found for hook "before_deploy". Error: TypeError: Can not read property "replace" from undefined

 at remove (/Volumes/Untitled/Plot/test/platforms/ios/cordova/node_modules/ios-sim/src/lib.js:282:70) at Array.forEach (native) at Object.getdevicetypes (/Volumes/Untitled/Plot/test/platforms/ios/cordova/node_modules/ios-sim/src/lib.js:292:22) at Object.listEmulatorImages [as run] (/Volumes/Untitled/Plot/test/platforms/ios/cordova/lib/list-emulator-images:34:29) at deployToSim (/Volumes/Untitled/Plot/test/platforms/ios/cordova/lib/run.js:146:50) at /Volumes/Untitled/Plot/test/platforms/ios/cordova/lib/run.js:88:20 at _fulfilled (/Volumes/Untitled/Plot/test/platforms/ios/cordova/node_modules/q/q.js:834:54) at self.promiseDispatch.done (/Volumes/Untitled/Plot/test/platforms/ios/cordova/node_modules/q/q.js:863:30) at Promise.promise.promiseDispatch (/Volumes/Untitled/Plot/test/platforms/ios/cordova/node_modules/q/q.js:796:13) at /Volumes/Untitled/Plot/test/platforms/ios/cordova/node_modules/q/q.js:604:44 

I tried removing and installing the cord again, but the problem still remains.

Please help me.

+42
ios npm cordova npm-install
Feb 20 '17 at 17:10
source share
9 answers

New solution

This problem has been fixed in the latest version of the "ios-sim" package (so now it is probably a simpler solution - compared to the old one, which is given below). To upgrade the ios-sim package to the latest version, run this in your terminal / cmd:

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

Old decision

The problem is that name_id_map[deviceName] returns undefined for iPad Pro (12.9-inch) and iPad Pro (10.5-inch) .

You can check it with console.log('name_id_map[ deviceName ]: ' + name_id_map[ deviceName ]); .

I fixed this error by adding if statements that check if the device is defined on " platforms / ios / cordova / node_modules / ios-sim / src / lib.js: 282 ".

I replaced this:

 list = []; var remove = function(runtime) { // remove "iOS" prefix in runtime, remove prefix "com.apple.CoreSimulator.SimDeviceType." in id list.push(util.format('%s, %s', name_id_map[ deviceName ].replace(/^com.apple.CoreSimulator.SimDeviceType./, ''), runtime.replace(/^iOS /, ''))); }; 

with this:

 list = []; var remove = function(runtime) { // remove "iOS" prefix in runtime, remove prefix "com.apple.CoreSimulator.SimDeviceType." in id if (name_id_map[deviceName] && runtime) { list.push(util.format('%s, %s', name_id_map[deviceName].replace(/^com.apple.CoreSimulator.SimDeviceType./, ''), runtime.replace(/^iOS /, ''))); } }; 

“IPad Pro Player (10.5-inch)” will not be on the list (but it probably doesn’t work anyway - it didn’t check).

Github bug report: https://github.com/phonegap/ios-sim/issues/210

+88
Jun 09 '17 at 6:58
source share

in the root of the project folder, cd platforms/ios/cordova && npm install ios-sim

+37
Jun 16 '17 at 3:35 on
source share

I had the same error. For me, I traced this in an error on the platforms / ios / cordova / node_modules / ios-sim / src / lib.js

 getdevicetypes: function(args) { ... list.devicetypes.forEach(function(device) { name_id_map[ filterDeviceName(device.name) ] = device.id; }); list = []; var remove = function(runtime) { // remove "iOS" prefix in runtime, remove prefix "com.apple.CoreSimulator.SimDeviceType." in id list.push(util.format('%s, %s', name_id_map[ deviceName ].replace(/^com.apple.CoreSimulator.SimDeviceType./, ''), runtime.replace(/^iOS /, ''))); }; 

The error always occurred as "TypeError: unable to read the" replace "property from undefined" in lib.js: 289

 list.push(util.format('%s, %s', name_id_map[ deviceName ].replace(/^com.apple.CoreSimulator.SimDeviceType./, ''), runtime.replace(/^iOS /, ''))); 

So, I inserted the debug code:

  list.devicetypes.forEach(function(device) { console.log('test 1 ' + device.name); console.log('test 2 ' + filterDeviceName(device.name)); name_id_map[ filterDeviceName(device.name) ] = device.id; }); 

It worked for me. Good luck.

  list = []; var remove = function(runtime) { // remove "iOS" prefix in runtime, remove prefix "com.apple.CoreSimulator.SimDeviceType." in id console.log('remove 1 ' + runtime); console.log('remove 2 ' + deviceName); console.log('remove 3 ' + name_id_map[ deviceName ]); list.push(util.format('%s, %s', name_id_map[ deviceName ].replace(/^com.apple.CoreSimulator.SimDeviceType./, ''), runtime.replace(/^iOS /, ''))); }; 

and got the following output:

 test 1 iPhone 5 test 2 iPhone 5 test 1 iPad Pro (9.7-inch) test 2 iPad Pro (9.7 inch) remove 1 iOS 10.2 remove 2 iPhone 5 remove 3 com.apple.CoreSimulator.SimDeviceType.iPhone-5 remove 1 iOS 10.2 remove 2 iPad Pro (9.7-inch) remove 3 undefined 

Note that filterDeviceName removed the minus character while filling the hash. When the value is restored again, the filter will not be applied, and the program will end with an error.

Fix bug: apply filter while writing and reading from hash.

  list.push(util.format('%s, %s', name_id_map[ filterDeviceName(deviceName) ].replace(/^com.apple.CoreSimulator.SimDeviceType./, ''), runtime.replace(/^iOS /, ''))); 
+15
Mar 31 '17 at 12:19
source share

Github has a PR that fixed my problem: https://github.com/phonegap/ios-sim/pull/213

Just called inside my project root

 nano platforms/ios/cordova/node_modules/ios-sim/src/lib.js 

and added a function to filter the device name, as indicated here: https://github.com/phonegap/ios-sim/pull/213/files

+8
Jun 14 '17 at 11:13 on
source share

I recently upgraded to xcode 8.3.3 and ionic 3.4.0

I deleted the ios-sim directory from myApp / platform / ios / cordova / node_modules and now it works.

+3
Jul 06 '17 at 9:17
source share

Another option is to use the cordova-ios version with the ios-sim patch already implemented

cordova platform add https://github.com/apache/cordova-ios.git#4.4.0-ios-sim

Remember that this is not an official version of Apache Cordova, it will be included in the next version 4.4.1.

+1
Jul 29 '17 at 13:43 on
source share

I just ran into this and thought that I would add something that worked for me - there was no npm install ios-sim solution.

All I did was open Xcode and it was pointing to the Generic iOS Device when I last used it when testing the application on a physical device. I just changed iOS Simulator to be on the list of iOS Simulator, repeated it, and it worked like a charm!

Hope this can help someone else in the same situation.

+1
09 Sep '17 at 12:04 on
source share

Upgrading the ios-sim version using npm install ios-sim@latest did not work for me. But if you find a good and easy solution on Github.

  • Open /platforms/ios/cordova/node_modules/ios-sim/src/lib.js
  • Search for deviceName using a code editor
  • Replace name_id_map[ deviceName ] with name_id_map[filterDeviceName(deviceName)]

You can find the github post here

+1
Sep 14 '17 at 13:09 on
source share

I ran the following commands and it solves my problem:

cd project_dir

sudo npm install ios-sim @latest

0
Aug 14 '17 at 13:47 on
source share



All Articles