From 51529018e52dd71cca08e3ad758c7285173f2b55 Mon Sep 17 00:00:00 2001 From: Eric Allam Date: Fri, 12 Jun 2026 16:38:37 +0100 Subject: [PATCH 1/2] fix(cli): point to init when dev or update runs without a project Running dev or update before a project existed crashed with a raw "Cannot find matching package.json" stack trace. The embedded version check and the config loader both resolved files up the tree before any friendly guidance could run; they now detect the missing project and point at npx trigger.dev@latest init. --- .changeset/cli-dev-without-project.md | 5 +++++ packages/cli-v3/src/commands/update.ts | 28 +++++++++++++++++++++++--- packages/cli-v3/src/config.ts | 26 +++++++++++++----------- 3 files changed, 44 insertions(+), 15 deletions(-) create mode 100644 .changeset/cli-dev-without-project.md diff --git a/.changeset/cli-dev-without-project.md b/.changeset/cli-dev-without-project.md new file mode 100644 index 00000000000..4b9172c6804 --- /dev/null +++ b/.changeset/cli-dev-without-project.md @@ -0,0 +1,5 @@ +--- +"trigger.dev": patch +--- + +Running `trigger.dev dev` (or `update`) before initializing a project no longer crashes with a raw `Cannot find matching package.json` stack trace. The CLI now detects the missing project and points you to `npx trigger.dev@latest init` instead. diff --git a/packages/cli-v3/src/commands/update.ts b/packages/cli-v3/src/commands/update.ts index f94718213f7..b7df5837f2e 100644 --- a/packages/cli-v3/src/commands/update.ts +++ b/packages/cli-v3/src/commands/update.ts @@ -66,13 +66,35 @@ export async function updateTriggerPackages( const projectPath = resolve(process.cwd(), dir); - const { packageJson, readonlyPackageJson, packageJsonPath } = await getPackageJson(projectPath); + let packageJsonResult: Awaited> | undefined; + + try { + packageJsonResult = await getPackageJson(projectPath); + } catch (error) { + // resolvePackageJSON throws when there's no package.json in projectPath or any parent + // directory — usually because the command ran before the project was set up. Don't crash + // with a raw stack trace; fall through to the actionable guidance below. + logger.debug("Failed to resolve package.json for update check", { projectPath, error }); + } + + if (!packageJsonResult?.packageJson) { + prettyError( + "No package.json found", + `Couldn't find a package.json in ${projectPath} or any parent directory.`, + "Run `npx trigger.dev@latest init` to set up your project, then try again." + ); + + // When embedded in another command (e.g. `dev`), there's nothing to run without a project, + // so stop here with a clean exit instead of letting the caller fail again downstream. + if (embedded) { + process.exit(1); + } - if (!packageJson) { - log.error("Failed to load package.json. Try to re-run with `-l debug` to see what's going on."); return false; } + const { packageJson, readonlyPackageJson, packageJsonPath } = packageJsonResult; + const newCliVersion = await updateCheck(); if (newCliVersion && !cliVersion.startsWith("0.0.0")) { diff --git a/packages/cli-v3/src/config.ts b/packages/cli-v3/src/config.ts index af5623e0176..1421cafe063 100644 --- a/packages/cli-v3/src/config.ts +++ b/packages/cli-v3/src/config.ts @@ -152,18 +152,9 @@ async function resolveConfig( overrides?: Partial, warn = true ): Promise { - const packageJsonPath = await resolvePackageJSON(cwd); - const tsconfigPath = await safeResolveTsConfig(cwd); - const lockfilePath = await resolveLockfile(cwd); - const workspaceDir = await findWorkspaceDir(cwd); - - const workingDir = result.configFile - ? dirname(result.configFile) - : packageJsonPath - ? dirname(packageJsonPath) - : cwd; - - // `trigger.config` is the fallback value set by c12 + // `trigger.config` is the fallback value set by c12. Bail out with actionable guidance before + // touching the filesystem: the pkg-types resolvers below throw raw errors when run outside a + // project (e.g. `dev` before `init`), which would mask this message. const missingConfigFile = !result.configFile || result.configFile === "trigger.config"; if (missingConfigFile) { @@ -178,6 +169,17 @@ async function resolveConfig( ); } + const packageJsonPath = await resolvePackageJSON(cwd); + const tsconfigPath = await safeResolveTsConfig(cwd); + const lockfilePath = await resolveLockfile(cwd); + const workspaceDir = await findWorkspaceDir(cwd); + + const workingDir = result.configFile + ? dirname(result.configFile) + : packageJsonPath + ? dirname(packageJsonPath) + : cwd; + const config = "config" in result.config ? (result.config.config as TriggerConfig) : result.config; From a5c9119be2722c22e178cf40d9b1a0490041a2f6 Mon Sep 17 00:00:00 2001 From: Eric Allam Date: Fri, 12 Jun 2026 17:17:56 +0100 Subject: [PATCH 2/2] docs(cli): broaden the changeset to cover deploy and preview --- .changeset/cli-dev-without-project.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/cli-dev-without-project.md b/.changeset/cli-dev-without-project.md index 4b9172c6804..4e5b74a7f68 100644 --- a/.changeset/cli-dev-without-project.md +++ b/.changeset/cli-dev-without-project.md @@ -2,4 +2,4 @@ "trigger.dev": patch --- -Running `trigger.dev dev` (or `update`) before initializing a project no longer crashes with a raw `Cannot find matching package.json` stack trace. The CLI now detects the missing project and points you to `npx trigger.dev@latest init` instead. +Running a CLI command like `dev`, `deploy`, `preview`, or `update` before initializing a project no longer crashes with a raw `Cannot find matching package.json` stack trace. The CLI now detects the missing project and points you to `npx trigger.dev@latest init` instead.