{"record":{"id":"9441d84355a561ce","repo":"composer/composer","slug":"file-s-cannot-be-found-in-the-current-directory","errorCode":null,"errorMessage":"File \"%s\" cannot be found in the current directory","messagePattern":"File \"(.+?)\" cannot be found in the current directory","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Composer/Command/BaseConfigCommand.php","lineNumber":79,"sourceCode":"            ($configFile === 'composer.json' || $configFile === './composer.json')\n            && !file_exists($configFile)\n            && realpath(Platform::getCwd()) === realpath($this->config->get('home'))\n        ) {\n            file_put_contents($configFile, \"{\\n}\\n\");\n        }\n\n        $this->configFile = new JsonFile($configFile, null, $io);\n        $this->configSource = new JsonConfigSource($this->configFile);\n\n        // Initialize the global file if it's not there, ignoring any warnings or notices\n        if ($input->getOption('global') && !$this->configFile->exists()) {\n            touch($this->configFile->getPath());\n            $this->configFile->write(['config' => new \\ArrayObject]);\n            Silencer::call('chmod', $this->configFile->getPath(), 0600);\n        }\n\n        if (!$this->configFile->exists()) {\n            throw new \\RuntimeException(sprintf('File \"%s\" cannot be found in the current directory', $configFile));\n        }\n    }\n\n    /**\n     * Get the local composer.json, global config.json, or the file passed by the user\n     */\n    protected function getComposerConfigFile(InputInterface $input, Config $config): string\n    {\n        return $input->getOption('global')\n            ? ($config->get('home') . '/config.json')\n            : ($input->getOption('file') ?? Factory::getComposerFile())\n        ;\n    }\n\n    /**\n     * Get the local auth.json or global auth.json, or if the user passed in a file to use,\n     * the corresponding auth.json\n     */","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/composer/composer/blob/6ffc1177404d0c50119c22dde6564a380f4a82c9/src/Composer/Command/BaseConfigCommand.php#L61-L97","documentation":"Thrown in BaseConfigCommand::initialize() when the resolved config file path does not exist on disk (and --global was not used, which would have created it). The sprintf fills in the resolved path so the user can see where Composer looked. This is a RuntimeException at initialization.","triggerScenarios":"Running `composer config --file does-not-exist.json ...`, or running a config command in a directory that has no composer.json and no explicit --file, where the default composer.json is absent.","commonSituations":"Wrong working directory (no composer.json present); a typo in the --file path; the file was deleted or never created; running config before `composer init`; paths with spaces or missing on case-sensitive filesystems.","solutions":["Verify the file path exists (ls the directory) and correct the --file value or cd to the project root.","Run `composer init` first to create a composer.json in the current project.","If targeting global config, use --global so Composer creates it automatically."],"exampleFix":"// before\ncomposer config --file mispelled.json extra.foo bar\n// after\ncomposer config --file composer.json extra.foo bar","handlingStrategy":"validation","validationCode":"$file = $input->getOption('file') ?? 'composer.json';\nif (!file_exists($file)) {\n    fwrite(STDERR, \"Config file not found: $file — run `composer init` first\\n\");\n    exit(1);\n}","typeGuard":"function configTargetExists(string $f): bool { return is_file($f) && is_readable($f); }","tryCatchPattern":null,"preventionTips":["Check file existence/readability before invoking a config command.","Run `composer init` in new projects to guarantee a composer.json."],"tags":["cli","filesystem","config"],"analyzedSha":"6ffc1177404d0c50119c22dde6564a380f4a82c9","analyzedAt":"2026-08-07T00:01:08.491Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}