davila7/claude-code-templates · warning

Could not parse package.json

Error message

Could not parse package.json

What it means

detectProject warns when it cannot read or JSON.parse the project's package.json while detecting Node frameworks. Detection simply skips Node framework detection and continues with other checks (Python, Ruby, etc.).

Source

Thrown at cli-tool/src/utils.js:31

      detectedLanguages.push('javascript-typescript');
      
      // Detect frameworks
      const dependencies = { ...packageJson.dependencies, ...packageJson.devDependencies };
      
      if (dependencies.react || dependencies['@types/react']) {
        detectedFrameworks.push('react');
      }
      if (dependencies.vue || dependencies['@vue/cli']) {
        detectedFrameworks.push('vue');
      }
      if (dependencies['@angular/core']) {
        detectedFrameworks.push('angular');
      }
      if (dependencies.express || dependencies.fastify || dependencies.koa) {
        detectedFrameworks.push('node');
      }
    } catch (error) {
      console.warn('Could not parse package.json');
    }
  }
  
  // Check for Python files
  const pythonFiles = await findFilesByExtension(targetDir, ['.py']);
  if (pythonFiles.length > 0) {
    detectedLanguages.push('python');
    
    // Check for Python frameworks
    const requirementsPath = path.join(targetDir, 'requirements.txt');
    const pipfilePath = path.join(targetDir, 'Pipfile');
    const pyprojectPath = path.join(targetDir, 'pyproject.toml');
    
    if (await fs.pathExists(requirementsPath)) {
      const requirements = await fs.readFile(requirementsPath, 'utf-8');
      if (requirements.includes('django')) detectedFrameworks.push('django');
      if (requirements.includes('flask')) detectedFrameworks.push('flask');
      if (requirements.includes('fastapi')) detectedFrameworks.push('fastapi');

View on GitHub (pinned to a0851ed10c)

Solutions

  1. Validate the file: npx jsonlint package.json or node -e "require('./package.json')"
  2. Fix the JSON syntax error (commas, quotes, conflict markers)
  3. Re-run the CLI so framework detection includes Node

Example fix

// before
{
  "name": "app",
  "scripts": { "dev": "vite" } // trailing stuff
}
// after
{
  "name": "app",
  "scripts": { "dev": "vite" }
}
Defensive patterns

Strategy: validation

Validate before calling

JSON.parse(require('fs').readFileSync('package.json', 'utf8')); // run in a precheck script or CI lint step

Type guard

function isValidPkg(o) { return o != null && typeof o === 'object'; }

Prevention

When it happens

Trigger: package.json exists but contains invalid JSON (trailing comma, comment, truncated file), or readFile throws due to permissions; the catch swallows the specific error message.

Common situations: Hand-edited package.json with a syntax error, merge-conflict markers left in the file, or a package.json with JSONC-style comments (some tools tolerate them, JSON.parse does not).

Related errors


AI-assisted analysis of davila7/claude-code-templates@a0851ed10c (2026-08-28). Data as JSON: /api/errors/ae7b9c12687bc37a. Report an issue: GitHub.