Skip to content

Commit

Permalink
better error handling when package.json not found
Browse files Browse the repository at this point in the history
  • Loading branch information
TMisiukiewicz committed Sep 18, 2023
1 parent 572439d commit 5a35401
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/cli-platform-ios/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*
*/
import chalk from 'chalk';
import path from 'path';
import fs from 'fs';
import findPodfilePath from './findPodfilePath';
Expand Down Expand Up @@ -67,12 +68,20 @@ export function dependencyConfig(
return null;
}

let version = '';
let version = 'unresolved';

try {
const packageJson = require(path.join(folder, 'package.json'));
version = packageJson.version;

if (packageJson.version) {
version = packageJson.version;
}
} catch {
throw new CLIError(`Could not read package.json file from ${folder}`);
throw new CLIError(
`Failed to locate package.json file from ${chalk.underline(
folder,
)}. This is most likely issue with your node_modules folder being corrupted. Please force install dependencies and try again`,
);
}

return {
Expand Down

0 comments on commit 5a35401

Please sign in to comment.