{"record":{"id":"e765bdc87654e818","repo":"symfony/symfony","slug":"package-s-listed-for-removal-was-not-found-in","errorCode":null,"errorMessage":"Package \"%s\" listed for removal was not found in \"importmap.php\".","messagePattern":"Package \"(.+?)\" listed for removal was not found in \"importmap\\.php\"\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Symfony/Component/AssetMapper/ImportMap/ImportMapManager.php","lineNumber":97,"sourceCode":"            unset($matches['version']);\n        }\n\n        return $matches;\n    }\n\n    /**\n     * @param PackageRequireOptions[] $packagesToRequire\n     * @param string[]                $packagesToRemove\n     *\n     * @return ImportMapEntry[]\n     */\n    private function updateImportMapConfig(bool $update, array $packagesToRequire, array $packagesToRemove, array $packagesToUpdate): array\n    {\n        $currentEntries = $this->importMapConfigReader->getEntries();\n\n        foreach ($packagesToRemove as $packageName) {\n            if (!$currentEntries->has($packageName)) {\n                throw new \\InvalidArgumentException(\\sprintf('Package \"%s\" listed for removal was not found in \"importmap.php\".', $packageName));\n            }\n\n            $this->cleanupPackageFiles($currentEntries->get($packageName));\n            $currentEntries->remove($packageName);\n        }\n\n        if ($update) {\n            foreach ($currentEntries as $entry) {\n                $importName = $entry->importName;\n                if (!$entry->isRemotePackage() || ($packagesToUpdate && !\\in_array($importName, $packagesToUpdate, true))) {\n                    continue;\n                }\n\n                $packagesToRequire[] = new PackageRequireOptions(\n                    $entry->packageModuleSpecifier,\n                    null,\n                    $importName,\n                    null,","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/symfony/symfony/blob/698e28026c22cf35d032cdb6e800db48b1535790/src/Symfony/Component/AssetMapper/ImportMap/ImportMapManager.php#L79-L115","documentation":"ImportMapManager::remove(array $packages) iterates the requested package names and checks $currentEntries->has($packageName); if any name is not present in importmap.php, InvalidArgumentException is thrown before any modification. It is an all-or-nothing guard: one unknown name aborts the whole removal (no partial state).","triggerScenarios":"Calling $importMapManager->remove(['react']) when 'react' is not in importmap.php; running bin/console importmap:uninstall react after it was already removed or never required; a typo in the package name passed to remove().","commonSituations":"Trying to remove a package whose import name differs from its npm name; double-removal; CI script removes a list including already-removed packages.","solutions":["Check the registered import name with bin/console debug:importmap before removing.","Remove only names that exist - filter your removal list against current entries first.","If using the CLI, run bin/console importmap:uninstall <exact-import-name>."],"exampleFix":"// before - blind removal\n$manager->remove(['react', 'lodash']); // 'lodash' missing -> throws\n\n// after - filter to existing entries\n$existing = $manager->/* or reader */ ;\n$toRemove = array_filter(['react','lodash'], fn($n) => $entries->has($n));\n$manager->remove($toRemove);","handlingStrategy":"validation","validationCode":"// Filter the removal list to entries that actually exist.\n$current = $importMapConfigReader->getEntries();\n$toRemove = array_filter($packages, fn($n) => $current->has($n));\nif ($toRemove) { $manager->remove($toRemove); }","typeGuard":"function packagesExist(ImportMapEntries $entries, array $names): bool {\n    foreach ($names as $n) { if (!$entries->has($n)) return false; }\n    return true;\n}","tryCatchPattern":"try {\n    $manager->remove($packages);\n} catch (\\InvalidArgumentException $e) {\n    if (str_contains($e->getMessage(), 'was not found in')) {\n        // recompute existing list, remove incrementally\n    } else { throw $e; }\n}","preventionTips":["Check bin/console debug:importmap before removing.","Make removal idempotent by filtering against current entries first.","Use exact import names, not npm names, when removing."],"tags":["asset-mapper","importmap","cli","validation","symfony"],"analyzedSha":"698e28026c22cf35d032cdb6e800db48b1535790","analyzedAt":"2026-08-06T23:40:49.025Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}