ruvnet/ruflo · error · Error
package.json not found
Error message
package.json not found
What it means
Publisher.publishToNpm() reads package.json from the directory passed to new Publisher(cwd) — defaulting to process.cwd() — and throws before build or publish if the file is missing. Every subsequent step (version read, private check, npm publish) depends on it, so the guard fires first.
Source
Thrown at v3/@claude-flow/deployment/src/publisher.ts:43
dryRun = false,
registry,
otp,
skipBuild = false,
buildCommand = 'npm run build'
} = options;
const result: PublishResult = {
packageName: '',
version: '',
tag,
success: false
};
try {
// Read package.json
const pkgPath = join(this.cwd, 'package.json');
if (!existsSync(pkgPath)) {
throw new Error('package.json not found');
}
const pkg: PackageInfo = JSON.parse(readFileSync(pkgPath, 'utf-8'));
if (pkg.private) {
throw new Error('Cannot publish private package');
}
result.packageName = pkg.name;
result.version = pkg.version;
// Run build if not skipped
if (!skipBuild) {
console.log('Building package...');
this.execCommand(buildCommand);
}
// Construct npm publish command arguments (without 'npm' prefix for execNpmCommand)View on GitHub (pinned to fa13ee4ad6)
Solutions
- Construct the Publisher with the package directory: new Publisher('packages/foo').publishToNpm(...)
- Or set the process cwd to the package before constructing (run the script from inside the package directory)
- Guard with existsSync(join(cwd, 'package.json')) before calling publishToNpm and fail with your own clearer message
Example fix
// before const publisher = new Publisher(); // cwd = monorepo root, no package.json there await publisher.publishToNpm(); // throws: package.json not found // after const publisher = new Publisher(join(repoRoot, 'packages/cli')); await publisher.publishToNpm();
Defensive patterns
Strategy: validation
Validate before calling
import { existsSync } from 'node:fs';
import { join } from 'node:path';
const pkgDir = join(repoRoot, 'packages/cli');
if (!existsSync(join(pkgDir, 'package.json'))) throw new Error(`no package.json in ${pkgDir}`);
await new Publisher(pkgDir).publishToNpm(); Prevention
- Always construct Publisher with an explicit package directory in monorepos
- Verify join(cwd, 'package.json') exists in release scripts before any publish call
When it happens
Trigger: new Publisher('/wrong/dir').publishToNpm(); running a release script from a monorepo root when the publishable package lives in packages/foo; default-cwd construction inside a CLI started outside any package directory.
Common situations: Monorepos where publishable packages sit in subdirectories; CI invoking the publish step from the repository root; typo in the cwd constructor argument.
Related errors
- package.json not found
- Cannot publish private package
- Failed to import OpenAI
- Pinata upload failed (HTTP ${res.status}): ${JSON.stringify(
- module loaded but is missing expected OAuth exports
AI-assisted analysis of ruvnet/ruflo@fa13ee4ad6 (2026-08-18).
Data as JSON: /api/errors/4ad2a83cbe0a59fc.
Report an issue: GitHub.