symfony/routing · error · InvalidArgumentException
The routing file " " must not specify both the "resource"…
Error message
The routing file "%s" must not specify both the "resource" key and the "path" key for "%s". Choose between an import and a route definition.
What it means
A single routing definition may be either an import (resource) or a concrete route (path), but not both. validate() throws an InvalidArgumentException when a definition specifies both 'resource' and 'path' keys, since the two are mutually exclusive.
Solutions
- Keep only 'resource' if the entry should import another file; delete the 'path' key.
- Keep only 'path' (plus controller etc.) if it is a concrete route; delete the 'resource' key.
- Split into two separate named definitions if you need both an import and a route.
Example fix
# before
home:
resource: routes/home.yaml
path: /
# after
home:
resource: routes/home.yaml Defensive patterns
Strategy: validation
Validate before calling
if (isset($config['resource']) && isset($config['path'])) { throw new \InvalidArgumentException('resource and path are mutually exclusive'); } Try / catch
try { $loader->load($file); } catch (\InvalidArgumentException $e) { /* split the definition or drop one key */ } Prevention
- Treat 'resource' and 'path' as either/or per definition.
- Check merged config output for combined keys.
- Split imports and routes into separate named entries.
When it happens
Trigger: A YAML/PHP definition like `home: { resource: routes/, path: / }` — combining an import with a route path, often after merging config fragments or copy-paste edits.
Common situations: Merging route config arrays where defaults and imports got combined; editing an import into a route (or vice versa) without removing the old key; config merge tools concatenating both branches.
Related errors
- The definition of " " in " " must be an array.
- The routing file " " contains unsupported keys for " ": "…
- The "type" key for the route definition
- You must define a "path" for the route
- The routing file " " must not specify both the "controller"…
AI-assisted analysis of symfony/routing@83fa223250 (2026-09-14).
Data as JSON: /api/errors/c29068c79a08b447.
Report an issue: GitHub.
Appendix: source
Thrown at Loader/ContentLoaderTrait.php:220
/**
* @throws \InvalidArgumentException If one of the provided config keys is not supported,
* something is missing or the combination is nonsense
*/
private function validate(mixed $config, string $name, string $path): void
{
if (!\is_array($config)) {
throw new \InvalidArgumentException(\sprintf('The definition of "%s" in "%s" must be an array.', $name, $path));
}
if (isset($config['alias'])) {
$this->validateAlias($config, $name, $path);
return;
}
if ($extraKeys = array_diff(array_keys($config), self::AVAILABLE_KEYS)) {
throw new \InvalidArgumentException(\sprintf('The routing file "%s" contains unsupported keys for "%s": "%s". Expected one of: "%s".', $path, $name, implode('", "', $extraKeys), implode('", "', self::AVAILABLE_KEYS)));
}
if (isset($config['resource']) && isset($config['path'])) {
throw new \InvalidArgumentException(\sprintf('The routing file "%s" must not specify both the "resource" key and the "path" key for "%s". Choose between an import and a route definition.', $path, $name));
}
if (!isset($config['resource']) && isset($config['type'])) {
throw new \InvalidArgumentException(\sprintf('The "type" key for the route definition "%s" in "%s" is unsupported. It is only available for imports in combination with the "resource" key.', $name, $path));
}
if (!isset($config['resource']) && !isset($config['path'])) {
throw new \InvalidArgumentException(\sprintf('You must define a "path" for the route "%s" in file "%s".', $name, $path));
}
if (isset($config['controller']) && isset($config['defaults']['_controller'])) {
throw new \InvalidArgumentException(\sprintf('The routing file "%s" must not specify both the "controller" key and the defaults key "_controller" for "%s".', $path, $name));
}
if (isset($config['stateless']) && isset($config['defaults']['_stateless'])) {
throw new \InvalidArgumentException(\sprintf('The routing file "%s" must not specify both the "stateless" key and the defaults key "_stateless" for "%s".', $path, $name));
}
if (isset($config['firewall']) && isset($config['defaults']['_firewall'])) {
throw new \InvalidArgumentException(\sprintf('The routing file "%s" must not specify both the "firewall" key and the defaults key "_firewall" for "%s".', $path, $name));
}
}
View on GitHub (pinned to 83fa223250)