{"record":{"id":"55c08d0af63c8532","repo":"yamadashy/repomix","slug":"no-version-found-in-package-json","errorCode":null,"errorMessage":"No version found in package.json","messagePattern":"No version found in package\\.json","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/core/file/packageJsonParse.ts","lineNumber":11,"sourceCode":"import * as fs from 'node:fs/promises';\nimport path from 'node:path';\nimport * as url from 'node:url';\nimport { logger } from '../../shared/logger.js';\n\nexport const getVersion = async (): Promise<string> => {\n  try {\n    const packageJson = await parsePackageJson();\n\n    if (!packageJson.version) {\n      logger.warn('No version found in package.json');\n      return 'unknown';\n    }\n\n    return packageJson.version;\n  } catch (error) {\n    logger.error('Error reading package.json:', error);\n    return 'unknown';\n  }\n};\n\nconst parsePackageJson = async (): Promise<{\n  name: string;\n  version: string;\n}> => {\n  const dirName = url.fileURLToPath(new URL('.', import.meta.url));\n  const packageJsonPath = path.join(dirName, '..', '..', '..', 'package.json');\n  const packageJsonFile = await fs.readFile(packageJsonPath, 'utf-8');\n  const packageJson = JSON.parse(packageJsonFile);","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/yamadashy/repomix/blob/f465ad909315a22120636baf03fa5e28701a50cb/src/core/file/packageJsonParse.ts#L1-L29","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before: package.json missing version\n{ \"name\": \"my-repo\" }\n// after\n$ npm pkg set version=1.0.0","handlingStrategy":"fallback","validationCode":"const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));\nif (!pkg.version) throw new Error('package.json has no version field');","typeGuard":"const hasVersion = (pkg) => typeof pkg?.version === 'string' && pkg.version.length > 0;","tryCatchPattern":"let version = 'unknown';\ntry { const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); if (hasVersion(pkg)) version = pkg.version; } catch (e) { /* keep fallback */ }","preventionTips":["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."],"tags":["package-json","version","metadata"],"backgroundTag":"missing-package-json-version","analyzedSha":"f465ad909315a22120636baf03fa5e28701a50cb","analyzedAt":"2026-08-29T01:27:42.024Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}