Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Conversation

oney
Copy link
Contributor

@oney oney commented Dec 6, 2015

In first version(not install any update from CodePush), we will get [CodePush] An unknown error occurred. after calling CodePush.sync();.
In CodePush.js line 55

console.log('localPackage', localPackage); // -> { failedInstall: false, isFirstRun: false }

if (localPackage && semver.compare(localPackage.appVersion, config.appVersion) === 0) {
 queryPackage = localPackage;
}

Because localPackage.appVersion is undefined, semver.compare will throw an exception.

try {
  semver.compare(localPackage.appVersion, config.appVersion);
} catch (e) {
  console.log('This is an error', e);
}

Logs are

'This is an error', { [TypeError: Invalid Version: undefined]
  line: 57942,
  column: 20,
  sourceURL: 'http://localhost:8081/index.ios.bundle?platform=ios&dev=true' }

So, just check localPackage.appVersion first then compare them.

@lostintangent
Copy link
Member

LGTM! I obviously forgot to test this change in an app with no previous updates. Thanks for this contribution @oney!

lostintangent added a commit that referenced this pull request Dec 6, 2015
Fix semver compare when first version
@lostintangent lostintangent merged commit 5b6fbdb into microsoft:master Dec 6, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants