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
- Open yarn.lock at the reported line:col and fix the structural error.
- Regenerate the lockfile: `rm yarn.lock && yarn install`.
- If in a merge, re-resolve the conflict and run `yarn install` to rewrite the lockfile.
- 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
- Treat yarn.lock as machine-generated; avoid manual structural edits.
- After merging branches, run `yarn install` to let Yarn normalize the lockfile.
- Restore yarn.lock from git rather than hand-repairing after corruption.
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
- Invalid number of spaces
- lockfileExists
- frozenLockfileError
- noRequiredLockfile
- Error parsing JSON at $0, $1.
AI-assisted analysis of yarnpkg/yarn@c2dda503f3 (2026-08-13).
Data as JSON: /api/errors/33a1a78d530b37e2.
Report an issue: GitHub.