From 4f4bbd7315f0ada5326d4b6b87c953e9a914bc9c Mon Sep 17 00:00:00 2001 From: rosen-vladimirov Date: Fri, 15 Jun 2018 13:58:24 +0300 Subject: [PATCH] fix: Unable to run app on iOS in Sidekick When trying to run application on iOS in Sidekick for the first time (when the iOS platform is not added yet to the project), the run fails with error "Cannot read property version of undefined". The problem is in the call to `platformLiveSyncService.prepareForLiveSync` which tries to start parsing device logs before starting the liveSync action. However, at this point, the application does not have the platform added yet and the code that tries to get the version of `tns-ios` from project's package.json fails. In order to resolve this, ensure the code for getting framework version from package.json will return undefined instead of failing. When undefined is returned, we know CLI will add the latest compatible iOS runtime version. We know that this version will print the port for debugging in the logs, so we can safely start parsing the logs. --- lib/services/ios-debugger-port-service.ts | 2 +- lib/services/platform-project-service-base.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/services/ios-debugger-port-service.ts b/lib/services/ios-debugger-port-service.ts index f7f2ebc19c..09cd825142 100644 --- a/lib/services/ios-debugger-port-service.ts +++ b/lib/services/ios-debugger-port-service.ts @@ -51,7 +51,7 @@ export class IOSDebuggerPortService implements IIOSDebuggerPortService { private canStartLookingForDebuggerPort(data: IProjectDir): boolean { const projectData = this.$projectDataService.getProjectData(data && data.projectDir); const frameworkVersion = this.$iOSProjectService.getFrameworkVersion(projectData); - return semver.gt(frameworkVersion, IOSDebuggerPortService.MIN_REQUIRED_FRAMEWORK_VERSION); + return !frameworkVersion || semver.gt(frameworkVersion, IOSDebuggerPortService.MIN_REQUIRED_FRAMEWORK_VERSION); } @cache() diff --git a/lib/services/platform-project-service-base.ts b/lib/services/platform-project-service-base.ts index 2b7dc9fec0..49e5d26b23 100644 --- a/lib/services/platform-project-service-base.ts +++ b/lib/services/platform-project-service-base.ts @@ -13,7 +13,8 @@ export abstract class PlatformProjectServiceBase extends EventEmitter implements } public getFrameworkVersion(projectData: IProjectData): string { - return this.$projectDataService.getNSValue(projectData.projectDir, this.getPlatformData(projectData).frameworkPackageName).version; + const frameworkData = this.$projectDataService.getNSValue(projectData.projectDir, this.getPlatformData(projectData).frameworkPackageName); + return frameworkData && frameworkData.version; } protected getAllNativeLibrariesForPlugin(pluginData: IPluginData, platform: string, filter: (fileName: string, _pluginPlatformsFolderPath: string) => boolean): string[] {