yamadashy/repomix · warning
No version found in package.json
Error message
No version found in package.json
What it means
getVersion reads package.json and, when parsed successfully but no version field is present, warns and returns the literal string "unknown". Callers (e.g. --version output, generated file headers) will show "unknown" instead of failing.
Source
Thrown at src/core/file/packageJsonParse.ts:11
import * as fs from 'node:fs/promises';
import path from 'node:path';
import * as url from 'node:url';
import { logger } from '../../shared/logger.js';
export const getVersion = async (): Promise<string> => {
try {
const packageJson = await parsePackageJson();
if (!packageJson.version) {
logger.warn('No version found in package.json');
return 'unknown';
}
return packageJson.version;
} catch (error) {
logger.error('Error reading package.json:', error);
return 'unknown';
}
};
const parsePackageJson = async (): Promise<{
name: string;
version: string;
}> => {
const dirName = url.fileURLToPath(new URL('.', import.meta.url));
const packageJsonPath = path.join(dirName, '..', '..', '..', 'package.json');
const packageJsonFile = await fs.readFile(packageJsonPath, 'utf-8');
const packageJson = JSON.parse(packageJsonFile);View on GitHub (pinned to f465ad9093)
Solutions
- Add a version field to package.json: `npm pkg set version=1.0.0`.
- Run repomix via the installed npm package instead of a raw source checkout so the correct package.json with version is found.
- If version isn't needed, ignore the warning — behavior is unaffected and version shows as "unknown".
- Check you're not pointing NODE_PATH or cwd at a different, version-less package.json.
Example fix
// before: package.json missing version
{ "name": "my-repo" }
// after
$ npm pkg set version=1.0.0 Defensive patterns
Strategy: fallback
Validate before calling
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
if (!pkg.version) throw new Error('package.json has no version field'); Type guard
const hasVersion = (pkg) => typeof pkg?.version === 'string' && pkg.version.length > 0;
Try / catch
let version = 'unknown';
try { const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); if (hasVersion(pkg)) version = pkg.version; } catch (e) { /* keep fallback */ } Prevention
- Keep a version field in package.json even for private packages (`npm pkg set version=...`).
- Run repomix from the installed package rather than a stripped source checkout.
- Check publish/bundle scripts don't strip the version field.
When it happens
Trigger: package.json exists and parses but lacks a version property — typical for private/workspace-root packages, repomix run from a source checkout of a modified package.json, or monorepo roots without a version.
Common situations: Running from a git clone where version was stripped; tools that rewrite package.json (publish scripts, bundlers) removing version; testing a fork without a version bump.
AI-assisted analysis of yamadashy/repomix@f465ad9093 (2026-08-29).
Data as JSON: /api/errors/55c08d0af63c8532.
Report an issue: GitHub.