Skip to content

Commit 128db32

Browse files
committed
fix(cli): show actionable message instead of crashing when package.json is missing
1 parent 002c441 commit 128db32

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"trigger.dev": patch
3+
---
4+
5+
`trigger dev` now shows an actionable message instead of crashing when no `package.json` is found.

packages/cli-v3/src/commands/update.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,18 @@ export async function updateTriggerPackages(
6666

6767
const projectPath = resolve(process.cwd(), dir);
6868

69-
const { packageJson, readonlyPackageJson, packageJsonPath } = await getPackageJson(projectPath);
69+
let packageJson: PackageJson;
70+
let readonlyPackageJson: PackageJson;
71+
let packageJsonPath: string;
7072

71-
if (!packageJson) {
72-
log.error("Failed to load package.json. Try to re-run with `-l debug` to see what's going on.");
73-
return false;
73+
try {
74+
({ packageJson, readonlyPackageJson, packageJsonPath } = await getPackageJson(projectPath));
75+
} catch {
76+
// `getPackageJson` throws when no package.json is found — show an
77+
// actionable message instead of crashing with a raw stack trace.
78+
throw new OutroCommandError(
79+
`Couldn't find a package.json in ${projectPath} (or any parent directory). Run this command from your project's root directory. If you haven't set up a project yet, create one first (e.g. \`npm init -y\`), then run \`npx trigger.dev@latest init\`.`
80+
);
7481
}
7582

7683
const newCliVersion = await updateCheck();

0 commit comments

Comments
 (0)