{"record":{"id":"4655020c0b6ecc23","repo":"composer/composer","slug":"the-package-name-s-is-invalid-it-should-be-lower","errorCode":null,"errorMessage":"The package name %s is invalid, it should be lowercase and have a vendor name, a forward slash, and a package name, matching: [a-z0-9_.-]+/[a-z0-9_.-]+","messagePattern":"The package name (.+?) is invalid, it should be lowercase and have a vendor name, a forward slash, and a package name, matching: \\[a-z0-9_\\.-\\]\\+/\\[a-z0-9_\\.-\\]\\+","errorType":"validation","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Composer/Command/InitCommand.php","lineNumber":90,"sourceCode":"\nRead more at https://getcomposer.org/doc/03-cli.md#init\nEOT\n            )\n        ;\n    }\n\n    /**\n     * @throws \\Seld\\JsonLint\\ParsingException\n     */\n    protected function execute(InputInterface $input, OutputInterface $output): int\n    {\n        $io = $this->getIO();\n\n        $allowlist = ['name', 'description', 'author', 'type', 'homepage', 'require', 'require-dev', 'stability', 'license', 'autoload'];\n        $options = array_filter(array_intersect_key($input->getOptions(), array_flip($allowlist)), static function ($val) { return $val !== null && $val !== []; });\n\n        if (isset($options['name']) && !Preg::isMatch('{^[a-z0-9]([_.-]?[a-z0-9]+)*\\/[a-z0-9](([_.]|-{1,2})?[a-z0-9]+)*$}D', $options['name'])) {\n            throw new \\InvalidArgumentException(\n                'The package name '.$options['name'].' is invalid, it should be lowercase and have a vendor name, a forward slash, and a package name, matching: [a-z0-9_.-]+/[a-z0-9_.-]+'\n            );\n        }\n\n        if (isset($options['author'])) {\n            $options['authors'] = $this->formatAuthors($options['author']);\n            unset($options['author']);\n        }\n\n        $repositories = $input->getOption('repository');\n        if (count($repositories) > 0) {\n            $config = Factory::createConfig($io);\n            foreach ($repositories as $repo) {\n                $options['repositories'][] = RepositoryFactory::configFromString($io, $config, $repo, true);\n            }\n        }\n\n        if (isset($options['stability'])) {","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/composer/composer/blob/c435d285c9120efdca35696769c72ea9fdcc0466/src/Composer/Command/InitCommand.php#L72-L108","documentation":"When `composer init` is run non-interactively with `--name`, InitCommand::execute validates the value against the strict package-name regex `^[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9](([_.]|-{1,2})?[a-z0-9]+)*$`. It requires lowercase alphanumerics, exactly one slash separating vendor and package, and no leading/trailing separators. Anything else throws InvalidArgumentException immediately.","triggerScenarios":"Calling `composer init --name=<value>` in a non-TTY context where <value> has uppercase letters, spaces, backslashes, multiple slashes, a missing vendor part, or starts/ends with a separator — e.g. `--name=MyApp/Foo`, `--name=myapp`, `--name=foo//bar`.","commonSituations":"Copying a PHP namespace (with backslashes or capitals) as the package name; forgetting the vendor prefix; pasting a name from a URL.","solutions":["Lowercase the entire name and split it as vendor/package: e.g. `mycompany/my-package`.","Replace invalid characters (- and _ are allowed; spaces/backslashes are not).","If you only have a name, add a vendor prefix from your github.user/USERNAME or COMPOSER_DEFAULT_VENDOR."],"exampleFix":"// before\ncomposer init --name=\"MyCompany/MyPackage\"\n// after\ncomposer init --name=\"mycompany/my-package\"","handlingStrategy":"validation","validationCode":"$name = $input->getOption('name');\nif ($name !== null && !preg_match('{^[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9](([_.]|-{1,2})?[a-z0-9]+)*$}D', $name)) {\n    throw new \\InvalidArgumentException('Refusing to run init: bad package name');\n}","typeGuard":"function isValidPackageName(string $name): bool {\n    return (bool) preg_match('{^[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9](([_.]|-{1,2})?[a-z0-9]+)*$}D', $name);\n}","tryCatchPattern":null,"preventionTips":["Always lowercase vendor/package names.","Generate the name from a PSR-4 namespace by lowercasing and replacing separators."],"tags":["init-command","validation","package-name","regex"],"backgroundTag":null,"analyzedSha":"c435d285c9120efdca35696769c72ea9fdcc0466","analyzedAt":"2026-08-07T18:58:23.525Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}