{"record":{"id":"55d5f544ce946a87","repo":"yarnpkg/yarn","slug":"invalid-number-of-spaces","errorCode":null,"errorMessage":"Invalid number of spaces","messagePattern":"Invalid number of spaces","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/lockfile/parse.js","lineNumber":89,"sourceCode":"    } else if (input[0] === '#') {\n      chop++;\n\n      let nextNewline = input.indexOf('\\n', chop);\n      if (nextNewline === -1) {\n        nextNewline = input.length;\n      }\n      const val = input.substring(chop, nextNewline);\n      chop = nextNewline;\n      yield buildToken(TOKEN_TYPES.comment, val);\n    } else if (input[0] === ' ') {\n      if (lastNewline) {\n        let indentSize = 1;\n        for (let i = 1; input[i] === ' '; i++) {\n          indentSize++;\n        }\n\n        if (indentSize % 2) {\n          throw new TypeError('Invalid number of spaces');\n        } else {\n          chop = indentSize;\n          yield buildToken(TOKEN_TYPES.indent, indentSize / 2);\n        }\n      } else {\n        chop++;\n      }\n    } else if (input[0] === '\"') {\n      let i = 1;\n      for (; i < input.length; i++) {\n        if (input[i] === '\"') {\n          const isEscaped = input[i - 1] === '\\\\' && input[i - 2] !== '\\\\';\n          if (!isEscaped) {\n            i++;\n            break;\n          }\n        }\n      }","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/yarnpkg/yarn/blob/c2dda503f3759b5be5f0e24ecd9cf5c97a540147/src/lockfile/parse.js#L71-L107","documentation":"Thrown as a `TypeError` by the lockfile tokenizer when a line begins with an odd number of leading spaces (`indentSize % 2 !== 0`). The yarn.lock format uses two-space indentation per level, so any odd indent count is syntactically invalid and the tokenizer refuses to guess the nesting level.","triggerScenarios":"A yarn.lock line is indented with 1, 3, 5, etc. spaces instead of an even number. Caused by manual editing, a bad merge, or an editor that mixed tabs and spaces (tab expansion to a non-multiple-of-2 width).","commonSituations":"Developer hand-edits yarn.lock and mis-indents. A merge tool conflits and leaves 3-space indent. An automated tool rewrites the lockfile with inconsistent indentation.","solutions":["Open yarn.lock and re-indent the offending line(s) to a multiple of two spaces.","Regenerate the lockfile from scratch: `rm yarn.lock && yarn install`.","Ensure your editor uses spaces (not tabs) for yarn.lock, or expand tabs consistently.","Resolve merge conflicts in yarn.lock cleanly."],"exampleFix":"# before (yarn.lock)\nreact@^16.0.0:\n   version \"16.8.0\"  # 3-space indent\n# after\nreact@^16.0.0:\n  version \"16.8.0\"  # 2-space indent","handlingStrategy":"validation","validationCode":"const fs = require('fs');\nfunction validateLockfileIndent(filePath) {\n  const lines = fs.readFileSync(filePath, 'utf8').split('\\n');\n  lines.forEach((line, idx) => {\n    const indent = line.match(/^( +)/);\n    if (indent && indent[1].length % 2 !== 0) {\n      console.error(`Odd indent (${indent[1].length} spaces) at line ${idx + 1}`);\n    }\n  });\n}\nvalidateLockfileIndent('yarn.lock');","typeGuard":null,"tryCatchPattern":"try {\n  const result = parseLockfile(lockfilePath);\n} catch (err) {\n  if (err instanceof TypeError && err.message === 'Invalid number of spaces') {\n    reporter.error('yarn.lock has odd indentation — regenerate with `rm yarn.lock && yarn install`.');\n    process.exit(1);\n  }\n  throw err;\n}","preventionTips":["Never hand-edit yarn.lock indentation; let Yarn rewrite it.","Configure your editor to use spaces (not tabs) for yarn.lock.","Regenerate the lockfile after any merge that touches it."],"tags":["lockfile","parse-error","indentation"],"backgroundTag":null,"analyzedSha":"c2dda503f3759b5be5f0e24ecd9cf5c97a540147","analyzedAt":"2026-08-13T04:17:06.305Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}