{"record":{"id":"89a225cb6293cd18","repo":"composer/composer","slug":"prefer-source-can-not-be-used-together-with-pr","errorCode":null,"errorMessage":"--prefer-source can not be used together with --prefer-install","messagePattern":"--prefer-source can not be used together with --prefer-install","errorType":"validation","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"warning","filePath":"src/Composer/Command/BaseCommand.php","lineNumber":347,"sourceCode":"            case 'source':\n                $preferSource = true;\n                break;\n            case 'dist':\n                $preferDist = true;\n                break;\n            case 'auto':\n            default:\n                // noop\n                break;\n        }\n\n        if (!$input->hasOption('prefer-dist') || !$input->hasOption('prefer-source')) {\n            return [$preferSource, $preferDist];\n        }\n\n        if ($input->hasOption('prefer-install') && is_string($input->getOption('prefer-install'))) {\n            if ($input->getOption('prefer-source')) {\n                throw new \\InvalidArgumentException('--prefer-source can not be used together with --prefer-install');\n            }\n            if ($input->getOption('prefer-dist')) {\n                throw new \\InvalidArgumentException('--prefer-dist can not be used together with --prefer-install');\n            }\n            switch ($input->getOption('prefer-install')) {\n                case 'dist':\n                    $input->setOption('prefer-dist', true);\n                    break;\n                case 'source':\n                    $input->setOption('prefer-source', true);\n                    break;\n                case 'auto':\n                    $preferDist = false;\n                    $preferSource = false;\n                    break;\n                default:\n                    throw new \\UnexpectedValueException('--prefer-install accepts one of \"dist\", \"source\" or \"auto\", got '.$input->getOption('prefer-install'));\n            }","sourceCodeStart":329,"sourceCodeEnd":365,"githubUrl":"https://github.com/composer/composer/blob/6ffc1177404d0c50119c22dde6564a380f4a82c9/src/Composer/Command/BaseCommand.php#L329-L365","documentation":"Thrown by BaseCommand::getPreferredInstallOptions() when both --prefer-source and --prefer-install are set on the same invocation. --prefer-install is the unified replacement flag and is mutually exclusive with the legacy --prefer-source.","triggerScenarios":"Running a command (install/update/require) with --prefer-source together with --prefer-install=<value>; getPreferredInstallOptions detects --prefer-install set as a string and --prefer-source also true.","commonSituations":"Copy-pasting flags from old scripts while adding the newer --prefer-install; CI configs accumulated over time; wrapper scripts passing both.","solutions":["Remove --prefer-source and keep --prefer-install=source (the modern equivalent).","Or drop --prefer-install and keep only --prefer-source (legacy).","Standardize on --prefer-install across scripts."],"exampleFix":"// before\ncomposer require pkg --prefer-source --prefer-install=dist\n// after\ncomposer require pkg --prefer-install=source","handlingStrategy":"validation","validationCode":"if ($input->getOption('prefer-install') !== null && $input->getOption('prefer-source')) {\n    throw new \\InvalidArgumentException('Use --prefer-install OR --prefer-source, not both');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Standardize on --prefer-install across all scripts.","Audit CI configs for legacy --prefer-source/-dist usage.","Document the mutually-exclusive nature in team runbooks."],"tags":["cli","install-options","php"],"analyzedSha":"6ffc1177404d0c50119c22dde6564a380f4a82c9","analyzedAt":"2026-08-07T00:01:08.491Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}