yarnpkg/yarn · error · MessageError
Invalid gist fragment $0.
Error message
Invalid gist fragment $0.
What it means
explodeGistFragment() splits a gist: fragment by '#'. If more than two parts result (more than one hash delimiter), the fragment is invalid. The valid format is gist:<id> or gist:<id>#<hash>.
Source
Thrown at src/resolvers/exotics/gist-resolver.js:22
import type {Manifest} from '../../types.js';
import type PackageRequest from '../../package-request.js';
import {MessageError} from '../../errors.js';
import GitResolver from './git-resolver.js';
import ExoticResolver from './exotic-resolver.js';
import * as util from '../../util/misc.js';
export function explodeGistFragment(fragment: string, reporter: Reporter): {id: string, hash: string} {
fragment = util.removePrefix(fragment, 'gist:');
const parts = fragment.split('#');
if (parts.length <= 2) {
return {
id: parts[0],
hash: parts[1] || '',
};
} else {
throw new MessageError(reporter.lang('invalidGistFragment', fragment));
}
}
export default class GistResolver extends ExoticResolver {
static protocol = 'gist';
constructor(request: PackageRequest, fragment: string) {
super(request, fragment);
const {id, hash} = explodeGistFragment(fragment, this.reporter);
this.id = id;
this.hash = hash;
}
id: string;
hash: string;
resolve(): Promise<Manifest> {View on GitHub (pinned to c2dda503f3)
Solutions
- Use the format gist:<id> or gist:<id>#<commit-hash>
- Remove any extra '#' characters from the gist dependency string
- Verify the gist id and optional commit hash are the only segments
Example fix
// before "my-dep": "gist:deadbeef#feature#x" // after "my-dep": "gist:deadbeef#abc123commit"
Defensive patterns
Strategy: validation
Validate before calling
function isValidGistFragment(fragment: string): boolean {
const cleaned = fragment.replace(/^gist:/, '');
return cleaned.split('#').length <= 2;
} Type guard
function isWellFormedGist(fragment: string): boolean {
const parts = fragment.replace(/^gist:/, '').split('#');
return parts.length <= 2 && parts[0].length > 0;
} Prevention
- Format gist dependencies as gist:<id> or gist:<id>#<hash>
- Avoid multiple '#' delimiters in dependency strings
- Validate exotic fragments before adding them to package.json
When it happens
Trigger: A dependency string like 'gist:abc#def#ghi' containing multiple '#' characters. Validated in the constructor of GistResolver via explodeGistFragment.
Common situations: Typos in gist dependency URLs; copy-paste errors appending extra fragments; mistaking the hash for a path separator.
Related errors
AI-assisted analysis of yarnpkg/yarn@c2dda503f3 (2026-08-13).
Data as JSON: /api/errors/86421ba02b8c1324.
Report an issue: GitHub.