yarnpkg/yarn · error · SyntaxError

${msg} ${this.token.line}:${this.token.col} in ${this.fileLo

Error message

${msg} ${this.token.line}:${this.token.col} in ${this.fileLoc}

What it means

Thrown as a `SyntaxError` by the parser's `unexpected()` method when the token stream does not match the expected grammar production. The message includes the human-readable context (`msg`), the line and column (`this.token.line:col`), and the file location (`fileLoc`). This is the generic lockfile syntax error for structurally invalid yarn.lock content beyond simple indent issues.

Source

Thrown at src/lockfile/parse.js:215

  }

  next(): Token {
    const item = this.tokens.next();
    invariant(item, 'expected a token');

    const {done, value} = item;
    if (done || !value) {
      throw new Error('No more tokens');
    } else if (value.type === TOKEN_TYPES.comment) {
      this.onComment(value);
      return this.next();
    } else {
      return (this.token = value);
    }
  }

  unexpected(msg: string = 'Unexpected token') {
    throw new SyntaxError(`${msg} ${this.token.line}:${this.token.col} in ${this.fileLoc}`);
  }

  expect(tokType: string) {
    if (this.token.type === tokType) {
      this.next();
    } else {
      this.unexpected();
    }
  }

  eat(tokType: string): boolean {
    if (this.token.type === tokType) {
      this.next();
      return true;
    } else {
      return false;
    }
  }

View on GitHub (pinned to c2dda503f3)

Solutions

  1. Open yarn.lock at the reported line:col and fix the structural error.
  2. Regenerate the lockfile: `rm yarn.lock && yarn install`.
  3. If in a merge, re-resolve the conflict and run `yarn install` to rewrite the lockfile.
  4. Restore from version control: `git checkout -- yarn.lock` then `yarn install`.

Example fix

# before (yarn.lock — missing colon / broken structure at reported line)
react@^16.0.0
  version "16.8.0"
# after
react@^16.0.0:
  version "16.8.0"
Defensive patterns

Strategy: try-catch

Validate before calling

const fs = require('fs');
function quickLockfileSanity(filePath) {
  const text = fs.readFileSync(filePath, 'utf8');
  for (const line of text.split('\n')) {
    // keys must end with ':' or be indented values
    if (line.length && !line.startsWith(' ') && !line.startsWith('#') && !line.endsWith(':')) {
      console.warn(`Possible malformed lockfile line: ${line}`);
    }
  }
}

Try / catch

try {
  await parseLockfile(fileLoc);
} catch (err) {
  if (err instanceof SyntaxError && err.message.includes('in')) {
    reporter.error(`Corrupt yarn.lock at ${err.message}. Regenerate: rm yarn.lock && yarn install`);
    process.exit(1);
  }
  throw err;
}

Prevention

When it happens

Trigger: The lockfile parser's `expect()`/`eat()` calls fail: e.g. a key without a colon, a value where a key is expected, a stray character. Triggered by `run()` when tokenization succeeds but grammar matching fails.

Common situations: Corrupted yarn.lock from a partial write or crash. Manual editing that broke structure. A merge conflict resolved by keeping both sides' text. Disk corruption.

Related errors


AI-assisted analysis of yarnpkg/yarn@c2dda503f3 (2026-08-13). Data as JSON: /api/errors/33a1a78d530b37e2. Report an issue: GitHub.