composer/composer · error · InvalidArgumentException
Invalid repository url (${repository}) given. Has to be a .j
Error message
Invalid repository url (${repository}) given. Has to be a .json file, an http url or a JSON object. What it means
Thrown by RepositoryFactory::configFromString() (src/Composer/Repository/RepositoryFactory.php:51) when the repository string matches none of the accepted forms: it does not start with 'http', is not a .json file path, and does not begin with '{' (a JSON object literal). The input is therefore unrecognizable as a repository specification.
Source
Thrown at src/Composer/Repository/RepositoryFactory.php:51
public static function configFromString(IOInterface $io, Config $config, string $repository, bool $allowFilesystem = false)
{
if (0 === stripos($repository, 'http')) {
$repoConfig = ['type' => 'composer', 'url' => $repository];
} elseif ("json" === pathinfo($repository, PATHINFO_EXTENSION)) {
$json = new JsonFile($repository, Factory::createHttpDownloader($io, $config));
$data = $json->read();
if (!empty($data['packages']) || !empty($data['includes']) || !empty($data['provider-includes'])) {
$repoConfig = ['type' => 'composer', 'url' => 'file://' . strtr(realpath($repository), '\\', '/')];
} elseif ($allowFilesystem) {
$repoConfig = ['type' => 'filesystem', 'json' => $json];
} else {
throw new \InvalidArgumentException("Invalid repository URL ($repository) given. This file does not contain a valid composer repository.");
}
} elseif (strpos($repository, '{') === 0) {
// assume it is a json object that makes a repo config
$repoConfig = JsonFile::parseJson($repository);
} else {
throw new \InvalidArgumentException("Invalid repository url (".Url::sanitize($repository).") given. Has to be a .json file, an http url or a JSON object.");
}
return $repoConfig;
}
public static function fromString(IOInterface $io, Config $config, string $repository, bool $allowFilesystem = false, ?RepositoryManager $rm = null): RepositoryInterface
{
$repoConfig = static::configFromString($io, $config, $repository, $allowFilesystem);
return static::createRepo($io, $config, $repoConfig, $rm);
}
/**
* @param array<string, mixed> $repoConfig
*/
public static function createRepo(IOInterface $io, Config $config, array $repoConfig, ?RepositoryManager $rm = null): RepositoryInterface
{
if (!$rm) {View on GitHub (pinned to 6ffc117740)
Solutions
- Use an https(s) URL, a path to a .json file, or a JSON object string (e.g. '{"type":"vcs","url":"https://github.com/vendor/pkg"}').
- For SSH git sources, wrap them in a full repository definition JSON with type 'vcs' rather than passing the bare SSH string.
- Double-check the extension and scheme of the supplied string.
Example fix
// before
// configFromString($io,$config,'git@github.com:vendor/pkg.git')
// after
// configFromString($io,$config,'{"type":"vcs","url":"git@github.com:vendor/pkg.git"}') Defensive patterns
Strategy: validation
Validate before calling
if (stripos($repository,'http')!==0
&& pathinfo($repository,PATHINFO_EXTENSION)!=='json'
&& !str_starts_with($repository,'{')) {
throw new \InvalidArgumentException('repository string must be an http url, .json path, or JSON object');
} Prevention
- Pass an https URL, a .json file path, or a JSON object string to configFromString.
- Wrap SSH/SCP git URLs in a full {"type":"vcs","url":...} object.
- Avoid bare SSH URLs and directory paths.
When it happens
Trigger: Calling configFromString() / fromString() with a string that is neither an http(s) URL, a path to a .json file, nor a JSON object string — e.g. a bare 'git@github.com:vendor/pkg.git' SSH url, or a plain word.
Common situations: Passing an SSH/SCP-style git URL ('git@host:owner/repo.git') instead of an https URL or a full repo config JSON; passing a directory path that is not a .json file; typos in the CLI repository argument.
Related errors
- Repository "${index}" (${repo}) must have a type defined
- "{source}" does not match the expected JSON schema
- "{file}" does not contain valid JSON {message}
- A repository of type "package" contains an invalid package d
- The json file must be an object ({})
AI-assisted analysis of composer/composer@6ffc117740 (2026-08-07).
Data as JSON: /api/errors/618743a168d8a3a7.
Report an issue: GitHub.