ios-sim: TypeError: Cannot read property 'replace' of undefined (lib.js:282)
The command line arguments i used for ios-sim:
./platforms/ios/cordova/lib/list-emulator-images
Expected behavior
Get a list of simulators.
Actual behavior.
TypeError: Cannot read property ‘replace’ of undefined in ios-sim/src/lib.js:282
Steps to reproduce the problem
Run “./platforms/ios/cordova/lib/list-emulator-images” in your cordova project.
System Specs
Please run the commands below in your Terminal.app and include it in the issue. Check when done and include results below.
- 1. system_profiler SPSoftwareDataType
System Software Overview:
System Version: macOS 10.12.5 (16F73)
Kernel Version: Darwin 16.6.0
Boot Volume: macOS
Boot Mode: Normal
Secure Virtual Memory: Enabled
System Integrity Protection: Enabled
- 2. ios-sim --version
5.0.12
- 3. xcodebuild -version
Xcode 8.3.3 Build version 8E3004b
- 4. xcode-select --print-path
/Applications/Xcode.app/Contents/Developer
- 5. node --version
v7.10.0
My solution
The solution for myself, because i don’t need the “iPad Pro (10.5-inch)” simulator if it even works (who knows):
The problem is that the name_id_map[deviceName]
returns undefined
for “iPad Pro (12.9-inch)” and “iPad Pro (10.5-inch)”.
I fixed this bug by adding an if statements which checks if the device is defined in “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 /, '')));
}
};
Link to the issue on stackoverflow: https://stackoverflow.com/a/44451292/7199922
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 13
- Comments: 28
@JedatKinports in your project folder root, do
cd platforms/ios/cordova && npm install ios-sim
cd platforms/ios/cordova/node_modules/ sudo npm install ios-sim@latest
It worked for me:
cd platforms/ios/cordova/ && npm install ios-sim&latest
In the meantime, I cherry-picked the ios-sim fix only and applied it to cordova-ios@4.4.0 To use:
cordova platform add https://github.com/apache/cordova-ios.git#4.4.0-ios-sim
This is not an official release of Apache Cordova.
Hm, maybe ios-sim is installed locally additionally? Then maybe try removing it.
(I’m trying to help people debug similar problems with Ionic, which uses Cordova under the hood: https://forum.ionicframework.com/t/error-cannot-read-property-replace-of-undefined-for-ios-sim/93663)
We added a simple hook for our build process:
config.xml
<hook src="hooks/update-ios-sim.js" type="before_deploy" />
hooks/update-ios-sim.js
I’ll try to get a cordova-ios platform release patch out soonest.
If anyone is wondering where the “local” ios-sim comes from and couldn’t find the
package.json
locally: https://github.com/apache/cordova-ios/blob/master/package.json#L49TypeError: Cannot read property ‘replace’ of undefined was the error, now I do reinstall android studio and everything works fine. thanks
This solved my problem as well!!! Thanks so much @JedatKinports !!!
Please beware not to edit the ios-sim source files of the wrong node_modules folder!!! The correct folder to edit the ios-sim source files is the one located at /cordova/platforms/ios/cordova/node_modules/ios-sim/src/lib.js.
(I had this problem through the Quasar-framework, please check to make sure you didn’t edit the wrong folder like I did.)
new to using the simulator … trying it for the first time tonight. The solution offered by anuragsoftware worked for me.
@JedatKinports this worked for me thanks!
After
npm i -g ios-sim
i removed the ios-sim directory insidemyApp/platforms/ios/cordova/node_modules
and now it’s working. Now it uses the global installed one i guess. Thanks! 😃Anyway, i couldn’t figure out, how to update the ios-sim local (inside my cordova project) package inside node_modules directory. Any idea how that could be done?
@piotrowski no it didn’t. The problem still exists. Even after the update to 5.1.0 with
npm i -g ios-sim
. Weird. Looks like the ios-sim version in the cordova project didn’t get updated. In the package.json it still says ios-sim@5.0.12, but if i execute ios-sim --version globally then i get the version: 5.1.0, any idea on how to update the ios-sim for my cordova project?