{"record":{"id":"bfdeacf8fae96e06","repo":"composer/composer","slug":"could-not-find-package-needle-in-your-project","errorCode":null,"errorMessage":"Could not find package \"{needle}\" in your project","messagePattern":"Could not find package \"(.+?)\" in your project","errorType":"console","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Composer/Command/BaseDependencyCommand.php","lineNumber":102,"sourceCode":"                return 1;\n            }\n\n            $repos[] = $localRepo;\n\n            $platformOverrides = $composer->getConfig()->get('platform') ?: [];\n            $repos[] = new PlatformRepository([], $platformOverrides);\n        }\n\n        $installedRepo = new InstalledRepository($repos);\n\n        // Parse package name and constraint\n        $needle = $input->getArgument(self::ARGUMENT_PACKAGE);\n        $textConstraint = $input->hasArgument(self::ARGUMENT_CONSTRAINT) ? $input->getArgument(self::ARGUMENT_CONSTRAINT) : '*';\n\n        // Find packages that are or provide the requested package first\n        $packages = $installedRepo->findPackagesWithReplacersAndProviders($needle);\n        if (empty($packages)) {\n            throw new \\InvalidArgumentException(sprintf('Could not find package \"%s\" in your project', $needle));\n        }\n\n        // If the version we ask for is not installed then we need to locate it in remote repos and add it.\n        // This is needed for why-not to resolve conflicts from an uninstalled version against installed packages.\n        $matchedPackage = $installedRepo->findPackage($needle, $textConstraint);\n        if (!$matchedPackage) {\n            $defaultRepos = new CompositeRepository(RepositoryFactory::defaultRepos($this->getIO(), $composer->getConfig(), $composer->getRepositoryManager()));\n            if ($match = $defaultRepos->findPackage($needle, $textConstraint)) {\n                $installedRepo->addRepository(new InstalledArrayRepository([clone $match]));\n            } elseif (PlatformRepository::isPlatformPackage($needle)) {\n                $parser = new VersionParser();\n                $constraint = $parser->parseConstraints($textConstraint);\n                if ($constraint->getLowerBound() !== Bound::zero()) {\n                    $tempPlatformPkg = new Package($needle, $constraint->getLowerBound()->getVersion(), $constraint->getLowerBound()->getVersion());\n                    $installedRepo->addRepository(new InstalledArrayRepository([$tempPlatformPkg]));\n                }\n            } else {\n                $this->getIO()->writeError('<error>Package \"'.$needle.'\" could not be found with constraint \"'.$textConstraint.'\", results below will most likely be incomplete.</error>');","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/composer/composer/blob/c435d285c9120efdca35696769c72ea9fdcc0466/src/Composer/Command/BaseDependencyCommand.php#L84-L120","documentation":"Thrown by BaseDependencyCommand (why/why-not) when findPackagesWithReplacersAndProviders() returns no packages matching the requested needle in the installed/locked repositories. The needle (first argument) must correspond to an installed package or one that is provided/replaced by an installed package. It signals the dependency is not present in the project.","triggerScenarios":"Running `composer why nonexistent/pkg`, misspelling a package name (`composer why monolog`), or querying a package that exists in the lock but under a different name (e.g. a provide/replace alias).","commonSituations":"Typo in package name, querying a transitive dependency by the wrong name, or running why before install so the package isn't in the installed repos. The message says \"in your project\" because it only searches local/locked repos, not all of packagist.","solutions":["Verify the exact package name with `composer show` (lists installed packages) or `composer show --installed`.","If the package is provided/replaced under another name, query that name instead.","Run `composer install`/`composer update` so the package is present in the local repo.","Check for typos against the package's canonical vendor/name on packagist.org."],"exampleFix":"// before\ncomposer why monolog\n// after\ncomposer why monolog/monolog","handlingStrategy":"validation","validationCode":"// Confirm the package is installed before running why/why-not:\nexec('composer show --installed 2>&1', $out, $code);\nif ($code !== 0 || !preg_grep('/^' . preg_quote($needle, '/') . '\\s/', $out)) {\n    fwrite(STDERR, \"$needle is not installed in this project\\n\");\n    exit(1);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run `composer show` to confirm exact installed package names before why/why-not.","Remember why only searches local/locked repos, not all of packagist."],"tags":["cli","dependencies","package-not-found"],"backgroundTag":null,"analyzedSha":"c435d285c9120efdca35696769c72ea9fdcc0466","analyzedAt":"2026-08-07T18:58:23.525Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}