doctrine/orm · error · InvalidArgumentException
Proxy directory cannot be null
Error message
Proxy directory cannot be null
What it means
orm:generate-proxies writes proxy classes either to the dest-path argument or, when that is omitted, to the directory configured on the EntityManager (Configuration::getProxyDir(), which defaults to null when never set). Running the command without an argument on such an unconfigured EntityManager throws InvalidArgumentException('Proxy directory cannot be null') before any work happens.
Source
Thrown at src/Tools/Console/Command/GenerateProxiesCommand.php:66
'https://github.com/doctrine/orm/pull/12005',
'Generating proxies is deprecated and will be impossible in Doctrine ORM 4.0.',
);
}
$ui = (new SymfonyStyle($input, $output))->getErrorStyle();
$em = $this->getEntityManager($input);
$metadatas = $em->getMetadataFactory()->getAllMetadata();
$metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter'));
// Process destination directory
$destPath = $input->getArgument('dest-path');
if ($destPath === null) {
$destPath = $em->getConfiguration()->getProxyDir();
if ($destPath === null) {
throw new InvalidArgumentException('Proxy directory cannot be null');
}
}
if (! is_dir($destPath)) {
mkdir($destPath, 0775, true);
}
$destPath = realpath($destPath);
if (! file_exists($destPath)) {
throw new InvalidArgumentException(
sprintf("Proxies destination directory '<info>%s</info>' does not exist.", $em->getConfiguration()->getProxyDir()),
);
}
if (! is_writable($destPath)) {
throw new InvalidArgumentException(
sprintf("Proxies destination directory '<info>%s</info>' does not have write permissions.", $destPath),View on GitHub (pinned to d9b9ff7301)
Solutions
- Pass the destination explicitly: php bin/console orm:generate-proxies var/cache/prod/doctrine/orm/Proxies.
- Or configure it once: $config->setProxyDir(__DIR__.'/var/cache/prod/doctrine/orm/Proxies') (doctrine-bundle: orm.proxy_dir).
- Prefer ORMSetup::createAttributeMetadataConfiguration(), which fills proxyDir with sys_get_temp_dir() when null is given.
Example fix
// before
$config = new Configuration(); // proxyDir stays null
$ php bin/console orm:generate-proxies
// InvalidArgumentException: Proxy directory cannot be null
// after
$config = ORMSetup::createAttributeMetadataConfiguration($paths, $devMode,
proxyDir: __DIR__ . '/var/cache/prod/doctrine/orm/Proxies'); Defensive patterns
Strategy: validation
Validate before calling
if ($em->getConfiguration()->getProxyDir() === null) {
throw new LogicException('Configure the proxy directory (setProxyDir) before generating proxies.');
}
// run orm:generate-proxies Try / catch
Catch \InvalidArgumentException around the command in build scripts and fail with an actionable message: 'set proxy_dir (doctrine.orm.proxy_dir) or pass a dest-path argument'.
Prevention
- Create Configuration via ORMSetup::create* helpers so the proxy directory defaults sensibly.
- Set orm.proxy_dir explicitly in Symfony config.
- Add a bootstrap assertion that getProxyDir() !== null in environments that generate proxies.
When it happens
Trigger: Running orm:generate-proxies without a dest-path argument when the Configuration never called setProxyDir() — typical with hand-rolled Configuration objects; setups relying on ORMSetup's temp-dir default but constructing Configuration directly.
Common situations: ORM 2 to 3+ upgrades where nothing assumes a proxy directory anymore; custom EntityManager factories; CI jobs that regenerate proxies on a minimal configuration.
Related errors
- Proxies destination directory '<info>%s</info>' does not exi
- Proxies destination directory '<info>%s</info>' does not hav
- No second-level cache is configured on the given EntityManag
- Missing arguments "--owner-class" "--association"
- No second-level cache is configured on the given EntityManag
AI-assisted analysis of doctrine/orm@d9b9ff7301 (2026-08-21).
Data as JSON: /api/errors/d9be3ebc3ddedd50.
Report an issue: GitHub.