cordova-ios icon indicating copy to clipboard operation
cordova-ios copied to clipboard

unable to run ios simulator, possible regression due to simctl update

Open CodeWithOz opened this issue 3 years ago • 9 comments

Bug Report

I'm no longer able to use cordova run to start my app with the iphone simulator. This was working on Saturday and it's no longer working today. The error message is:

Error: Unhandled error. ('[ios-sim] SyntaxError: Unexpected token u in JSON at position 0\n' +
  '    at JSON.parse (<anonymous>)\n' +
  '    at Object.list (/Users/{user}/Documents/{project}/node_modules/simctl/simctl.js:173:33)\n' +
  '    at getDeviceFromDeviceTypeId (/Users/{user}/Documents/{project}/node_modules/ios-sim/src/lib.js:155:21)\n' +
  '    at /Users/{user}/Documents/{project}/node_modules/ios-sim/src/lib.js:460:22\n' +
  '    at withInjectedEnvironmentVariablesToProcess (/Users/{user}/Documents/{project}/node_modules/ios-sim/src/lib.js:269:3)\n' +
  '    at /Users/{user}/Documents/{project}/node_modules/ios-sim/src/lib.js:457:7\n' +
  '    at tryParseBuffer (/Users/{user}/Documents/{project}/node_modules/ios-sim/node_modules/bplist-parser/bplistParser.js:25:5)\n' +
  '    at /Users/{user}/Documents/{project}/node_modules/ios-sim/node_modules/bplist-parser/bplistParser.js:33:7\n' +
  '    at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:63:3)\n')

I've also created an issue about this in the simctl repo.

Problem

simctl now throws an error when trying to get the details of the specified target device, as shown in that error message. The problem appears related to the changes discussed in this simctl issue which led to updating shelljs to fix a security vulnerability.

What is expected to happen?

cordova run completes without errors, which was happening as recently as 2 days ago.

What does actually happen?

See explanation above.

Information

cordova-ios 6.2.0 on m1 mac xcode 13

Command or Code

Try cordova run --emulator --noprepare --nobuild --target="iPhone-13, 15.2" --debug in a project.

Environment, Platform, Device

m1 mac with xcode 13, trying to run my app on any simulator device

Version information

cordova 11 cordova-ios 6.2.0

Checklist

  • [x] I searched for existing GitHub issues
  • [x] I updated all Cordova tooling to most recent version
  • [x] I included all the necessary information above

CodeWithOz avatar Jan 31 '22 16:01 CodeWithOz

/cc @shazron

timbru31 avatar Jan 31 '22 16:01 timbru31

@timbru31 @shazron what would be the "fast" way to return to using the version of simctl that doesn't contain the regression? I've tried cloning each dependency and updating the files but installing the final modified cordova-ios is giving an error that the cordova-ios platform failed to fetch.

CodeWithOz avatar Jan 31 '22 23:01 CodeWithOz

To be clear what I mean is that I forked cordova-ios and updated the package.json to use:

...
    "ios-sim": "github:CodeWithOz/ios-sim#fix-pin-simctl",
...

and the package-lock.json now has:

...
        "ios-sim": "github:CodeWithOz/ios-sim#fix-pin-simctl",
...
    "node_modules/ios-sim": {
      "version": "9.0.0",
      "resolved": "git+ssh://[email protected]/CodeWithOz/ios-sim.git#7471195884b9596e73934ab8a07c9836417cd35f",
      "license": "Apache-2.0",
      "dependencies": {
        "@oclif/command": "^1.5.18",
        "@oclif/config": "^1.13.3",
        "@oclif/errors": "^1.2.2",
        "@oclif/plugin-help": "^2.2.1",
        "bplist-parser": "^0.2.0",
        "debug": "^4.1.1",
        "nopt": "^4.0.1",
        "plist": "^3.0.1",
        "simctl": "2.0.0"
      },
      "bin": {
        "ios-sim": "bin/ios-sim"
      },
      "engines": {
        "node": ">=8"
      }
    },
...
    "ios-sim": {
      "version": "git+ssh://[email protected]/CodeWithOz/ios-sim.git#7471195884b9596e73934ab8a07c9836417cd35f",
      "from": "ios-sim@CodeWithOz/ios-sim#fix-pin-simctl",
      "requires": {
        "@oclif/command": "^1.5.18",
        "@oclif/config": "^1.13.3",
        "@oclif/errors": "^1.2.2",
        "@oclif/plugin-help": "^2.2.1",
        "bplist-parser": "^0.2.0",
        "debug": "^4.1.1",
        "nopt": "^4.0.1",
        "plist": "^3.0.1",
        "simctl": "2.0.0"
      },
      "dependencies": {
        "nopt": {
          "version": "4.0.3",
          "resolved": "https://registry.npmjs.org/nopt/-/nopt-4.0.3.tgz",
          "integrity": "sha512-CvaGwVMztSMJLOeXPrez7fyfObdZqNUK1cPAEzLHrTybIua9pMdmmPR5YwtfNftIOMv3DPUhFaxsZMNTQO20Kg==",
          "requires": {
            "abbrev": "1",
            "osenv": "^0.1.4"
          }
        }
      }
    },
...

I add the platform using cordova platform add -verbose https://github.com/CodeWithOz/cordova-ios#fix-ios-sim and get this as part of the error:

Using cordova-fetch for https://github.com/CodeWithOz/cordova-ios#fix-ios-sim
fetch: Installing https://github.com/CodeWithOz/cordova-ios#fix-ios-sim to /Users/{user}/Documents/{project}
Running command: npm install https://github.com/CodeWithOz/cordova-ios#fix-ios-sim --save-dev
Command finished with error code 1: npm install,https://github.com/CodeWithOz/cordova-ios#fix-ios-sim,--save-dev
Failed to fetch platform https://github.com/CodeWithOz/cordova-ios#fix-ios-sim
Probably this is either a connection problem, or platform spec is incorrect.
Check your connection and platform name/version/URL.
CordovaError: Error: npm: Command failed with exit code 1 Error output:
sh: oclif-dev: command not found
npm ERR! premature close

It seems the relevant line is Command finished with error code 1: npm install,https://github.com/CodeWithOz/cordova-ios#fix-ios-sim,--save-dev, so when I ran npm i directly in the cordova-ios folder I get a stream of errors like this (abbreviated because it's really really long):

...
npm WARN tar ENOENT: no such file or directory, lstat '/Users/{user}/Documents/cordova-ios/node_modules/.staging/rxjs-756692a8/src/operator'
npm WARN tar ENOENT: no such file or directory, open '/Users/{user}/Documents/cordova-ios/node_modules/.staging/rxjs-756692a8/src/operators/zipAll.ts'
npm WARN tar ENOENT: no such file or directory, open '/Users/{user}/Documents/cordova-ios/node_modules/.staging/rxjs-756692a8/_esm2015/LICENSE.txt'
...

Any ideas on what the solution could be for me?

CodeWithOz avatar Jan 31 '22 23:01 CodeWithOz

You can force cordova-ios to use the previous version of simctl as a temporary workaround. npm un simctl && npm i [email protected] -E -D

I tried using npm 8's overrides feature, but couldn't seem to get it working. Most likely because npm audit keeps ignoring the override and installing 2.0.1

almercier avatar Feb 01 '22 19:02 almercier

This also happened to me this past Friday this was working fine and on Monday, I get that exact same error even recloning the repo and reinstalling everything.

antares-farias avatar Feb 01 '22 19:02 antares-farias

There was a report that simctl was causing npm audit warnings on cordova-ios due to a vulnerable version of shelljs. This led to an update to simctl to pull in the latest version of shelljs, which seems to have breaking changes around how it handles stdio.

Installing cordova-ios as of Sunday will pull in the latest version of simctl, which currently has a non-vulnerable, but also non-working version of shelljs.

dpogue avatar Feb 01 '22 19:02 dpogue

Judging by the thread on the bug report on simctl, it seems like it might be an easy fix. Hoping it gets fixed quickly.

almercier avatar Feb 01 '22 20:02 almercier

what works for me was to directly install in the project the previews version of the simctl

npm install [email protected]

antares-farias avatar Feb 04 '22 18:02 antares-farias

[email protected] was just published with a fix. Sorry about this, I was away (public holidays)

shazron avatar Feb 09 '22 09:02 shazron