{"record":{"id":"3434f1b68bd3bea8","repo":"composer/composer","slug":"script-s-is-not-defined-in-this-package","errorCode":null,"errorMessage":"Script \"%s\" is not defined in this package","messagePattern":"Script \"(.+?)\" is not defined in this package","errorType":"validation","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Composer/Command/RunScriptCommand.php","lineNumber":125,"sourceCode":"        }\n\n        $script = $input->getArgument('script');\n        if ($script === null) {\n            throw new \\RuntimeException('Missing required argument \"script\"');\n        }\n\n        if (!in_array($script, $this->scriptEvents)) {\n            if (defined('Composer\\Script\\ScriptEvents::'.str_replace('-', '_', strtoupper($script)))) {\n                throw new \\InvalidArgumentException(sprintf('Script \"%s\" cannot be run with this command', $script));\n            }\n        }\n\n        $composer = $this->requireComposer();\n        $devMode = $input->getOption('dev') || !$input->getOption('no-dev');\n        $event = new ScriptEvent($script, $composer, $this->getIO(), $devMode);\n        $hasListeners = $composer->getEventDispatcher()->hasEventListeners($event);\n        if (!$hasListeners) {\n            throw new \\InvalidArgumentException(sprintf('Script \"%s\" is not defined in this package', $script));\n        }\n\n        $args = $input->getArgument('args');\n\n        if (null !== $timeout = $input->getOption('timeout')) {\n            if (!ctype_digit($timeout)) {\n                throw new \\RuntimeException('Timeout value must be numeric and positive if defined, or 0 for forever');\n            }\n            // Override global timeout set before in Composer by environment or config\n            ProcessExecutor::setTimeout((int) $timeout);\n        }\n\n        Platform::putEnv('COMPOSER_DEV_MODE', $devMode ? '1' : '0');\n\n        return $composer->getEventDispatcher()->dispatchScript($script, $devMode, $args);\n    }\n\n    protected function listScripts(OutputInterface $output): int","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/composer/composer/blob/c435d285c9120efdca35696769c72ea9fdcc0466/src/Composer/Command/RunScriptCommand.php#L107-L143","documentation":"Thrown when the requested script has no registered listeners — i.e. it is not defined under `scripts` in composer.json (and no plugin handles it). hasEventListeners() returns false, so dispatch would be a no-op and Composer rejects it instead. It is an \\InvalidArgumentException.","triggerScenarios":"Running `composer run-script <name>` where <name> is neither a custom script in composer.json `scripts` nor an event with plugin listeners (RunScriptCommand.php:123-125).","commonSituations":"Typo in script name; running in the wrong project (no composer.json or different one); script was removed/renamed; copy-paste from a tutorial whose script keys differ.","solutions":["List defined scripts with `composer run-script --list` and use an exact name.","Add the script to composer.json under `scripts` if it should exist.","Confirm you are in the project root that owns the composer.json defining the script.","Watch for case and hyphen vs underscore mismatches in the name."],"exampleFix":"// before\ncomposer run-script tesst\n// after (after `composer run-script --list`)\ncomposer run-script test","handlingStrategy":"validation","validationCode":"$data = json_decode((string) file_get_contents(getcwd() . '/composer.json'), true);\n$scripts = array_keys($data['scripts'] ?? []);\nif (!in_array($name, $scripts, true)) {\n    fwrite(STDERR, \"Script '$name' is not defined. Defined: \" . implode(', ', $scripts) . \"\\n\");\n    exit(1);\n}","typeGuard":"function scriptIsDefined(string $composerJson, string $name): bool\\n{\\n    $data = json_decode((string) file_get_contents($composerJson), true);\\n    return is_array($data) && isset($data['scripts'][$name]);\\n}","tryCatchPattern":"try {\\n    // run `composer run-script <name>`\\n} catch (\\InvalidArgumentException $e) {\\n    if (str_contains($e->getMessage(), 'is not defined in this package')) {\\n        // list scripts, fix the name, retry\\n    }\\n}","preventionTips":["Run `composer run-script --list` to copy exact script names.","Confirm you're in the project root that owns the composer.json defining the script.","Standardize script naming (lowercase, hyphen-separated) to avoid mismatches."],"tags":["cli","scripts","composer-json","user-input"],"backgroundTag":null,"analyzedSha":"c435d285c9120efdca35696769c72ea9fdcc0466","analyzedAt":"2026-08-07T18:58:23.525Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}