Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/dev-missing-package-json-message.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"trigger.dev": patch
---

`trigger dev` now shows an actionable message instead of crashing when no `package.json` is found.
15 changes: 11 additions & 4 deletions packages/cli-v3/src/commands/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,18 @@ export async function updateTriggerPackages(

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

const { packageJson, readonlyPackageJson, packageJsonPath } = await getPackageJson(projectPath);
let packageJson: PackageJson;
let readonlyPackageJson: PackageJson;
let packageJsonPath: string;

if (!packageJson) {
log.error("Failed to load package.json. Try to re-run with `-l debug` to see what's going on.");
return false;
try {
({ packageJson, readonlyPackageJson, packageJsonPath } = await getPackageJson(projectPath));
} catch {
// `getPackageJson` throws when no package.json is found — show an
// actionable message instead of crashing with a raw stack trace.
throw new OutroCommandError(
`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\`.`
);
}

const newCliVersion = await updateCheck();
Expand Down
Loading