New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property 'replace' of undefined (lib.js:282) #210

Closed
JedatKinports opened this Issue Jun 9, 2017 · 28 comments

Comments

Projects
None yet
@JedatKinports
Copy link

JedatKinports commented Jun 9, 2017

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

@janpio

This comment has been minimized.

Copy link

janpio commented Jun 9, 2017

There already is a ios-sim version 5.0.13. Does updating to this version (npm i -g ios-sim) fix the problem?

@JedatKinports

This comment has been minimized.

Copy link

JedatKinports commented Jun 9, 2017

@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?

@janpio

This comment has been minimized.

Copy link

janpio commented Jun 9, 2017

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)

@JedatKinports

This comment has been minimized.

Copy link

JedatKinports commented Jun 9, 2017

After npm i -g ios-sim 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! :)

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?

@theHellyar

This comment has been minimized.

Copy link

theHellyar commented Jun 9, 2017

@JedatKinports this worked for me thanks!

@janpio

This comment has been minimized.

Copy link

janpio commented Jun 9, 2017

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#L49

@shazron

This comment has been minimized.

Copy link

shazron commented Jun 9, 2017

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

@shazron

This comment has been minimized.

Copy link

shazron commented Jun 9, 2017

I'm closing this issue since it has actually been fixed in ios-sim. The workarounds for Cordova have also been shown.

@shazron shazron closed this Jun 9, 2017

@janpio

This comment has been minimized.

Copy link

janpio commented Jun 9, 2017

Is there a way to properly fix this in newly created projects? Ionic for example tends to treat everything in /platforms as disposable, so some people might get this problem over and over again...

@shazron

This comment has been minimized.

Copy link

shazron commented Jun 9, 2017

@piotrowski no. Ionic if they use cordova templates for project generation could add a hook or something.

@shazron

This comment has been minimized.

Copy link

shazron commented Jun 9, 2017

I'll try to get a cordova-ios platform release patch out soonest.

@janpio

This comment has been minimized.

Copy link

janpio commented Jun 9, 2017

@shazron Thank you. I will keep posting our workaround for now. At least we know how to fix it now, so 🥇 to you ;)

@JedatKinports

This comment has been minimized.

Copy link

JedatKinports commented Jun 9, 2017

@shazron platforms/ios/cordova/package.json doesn't exists. And there is only a node_modules directory not .node_modules. don't know if that matters. Doesn't matter as long as this fix works. Was just curious. ;)

@shazron

This comment has been minimized.

Copy link

shazron commented Jun 9, 2017

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.

@shazron shazron added this to the 5.0.13 milestone Jun 10, 2017

@anuragsoftware

This comment has been minimized.

Copy link

anuragsoftware commented Jun 10, 2017

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

@JedatKinports

This comment has been minimized.

Copy link

JedatKinports commented Jun 10, 2017

@anuragsoftware i tried that also, didn't work.

@Acciaiodigitale

This comment has been minimized.

Copy link

Acciaiodigitale commented Jun 11, 2017

sudo npm install ios-sim@5.0.12 works

@howardowens

This comment has been minimized.

Copy link

howardowens commented Jun 13, 2017

new to using the simulator ... trying it for the first time tonight. The solution offered by anuragsoftware worked for me.

@renatoalencar

This comment has been minimized.

Copy link

renatoalencar commented Jun 14, 2017

It worked for me:

cd platforms/ios/cordova/ && npm install ios-sim&latest

@jamesjara

This comment has been minimized.

Copy link

jamesjara commented Jun 16, 2017

It works cd platforms/ios/cordova/ && npm install ios-sim&latest or selecting a device

schiaudano pushed a commit to schiaudano/cordova-vue-boilerplate that referenced this issue Jun 25, 2017

stefano.chiaudano stefano.chiaudano
Added iOS platform
Fixed cordova run iOS missing ios-sim according to: ios-control/ios-sim#210
@mesqueeb

This comment has been minimized.

Copy link

mesqueeb commented Jun 26, 2017

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.)

@JedatKinports

This comment has been minimized.

Copy link

JedatKinports commented Jun 26, 2017

@mesqueeb you are welcome. :)

@kouskefil

This comment has been minimized.

Copy link

kouskefil commented Aug 5, 2017

Hi everyone, i'm begining with ionic and i get the same problem but with android. I would appreciate your helps. thanks in advance

@JedatKinports

This comment has been minimized.

Copy link

JedatKinports commented Aug 5, 2017

@kouskefil what kind of error do you get? I don't think that it's the exact same one. If it's not the same then i would suggest that you open a new issue.

@kouskefil

This comment has been minimized.

Copy link

kouskefil commented Aug 6, 2017

TypeError: Cannot read property 'replace' of undefined was the error, now I do reinstall android studio and everything works fine. thanks

@beesden

This comment has been minimized.

Copy link

beesden commented Aug 15, 2017

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

#!/usr/bin/env node
const fs = require('fs');
const execSync = require('child_process').execSync;

if (fs.existsSync('platforms/ios')) {
  execSync('cd platforms/ios/cordova && npm install ios-sim@latest');
}
@fabiancook

This comment has been minimized.

Copy link

fabiancook commented Aug 20, 2017

I resolved this issue by updating ios-sim on my global cordova install rather than local.

@prescottprue

This comment has been minimized.

Copy link

prescottprue commented Aug 22, 2017

Got it working with cd platforms/ios/cordova/ && npm install ios-sim@latest && cd .... (notice the & is replaced with @, and the final cd brings you back)

@beesden , I like your idea. Might try that out.

schiaudano pushed a commit to schiaudano/cordova-vue-seed that referenced this issue Sep 9, 2017

stefano.chiaudano stefano.chiaudano
Added iOS platform
Fixed cordova run iOS missing ios-sim according to: ios-control/ios-sim#210
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment