symfony/symfony · error · InvalidArgumentException

Package "%s" listed for removal was not found in "importmap.

Error message

Package "%s" listed for removal was not found in "importmap.php".

What it means

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).

Source

Thrown at src/Symfony/Component/AssetMapper/ImportMap/ImportMapManager.php:97

            unset($matches['version']);
        }

        return $matches;
    }

    /**
     * @param PackageRequireOptions[] $packagesToRequire
     * @param string[]                $packagesToRemove
     *
     * @return ImportMapEntry[]
     */
    private function updateImportMapConfig(bool $update, array $packagesToRequire, array $packagesToRemove, array $packagesToUpdate): array
    {
        $currentEntries = $this->importMapConfigReader->getEntries();

        foreach ($packagesToRemove as $packageName) {
            if (!$currentEntries->has($packageName)) {
                throw new \InvalidArgumentException(\sprintf('Package "%s" listed for removal was not found in "importmap.php".', $packageName));
            }

            $this->cleanupPackageFiles($currentEntries->get($packageName));
            $currentEntries->remove($packageName);
        }

        if ($update) {
            foreach ($currentEntries as $entry) {
                $importName = $entry->importName;
                if (!$entry->isRemotePackage() || ($packagesToUpdate && !\in_array($importName, $packagesToUpdate, true))) {
                    continue;
                }

                $packagesToRequire[] = new PackageRequireOptions(
                    $entry->packageModuleSpecifier,
                    null,
                    $importName,
                    null,

View on GitHub (pinned to 698e28026c)

Solutions

  1. Check the registered import name with bin/console debug:importmap before removing.
  2. Remove only names that exist - filter your removal list against current entries first.
  3. If using the CLI, run bin/console importmap:uninstall <exact-import-name>.

Example fix

// before - blind removal
$manager->remove(['react', 'lodash']); // 'lodash' missing -> throws

// after - filter to existing entries
$existing = $manager->/* or reader */ ;
$toRemove = array_filter(['react','lodash'], fn($n) => $entries->has($n));
$manager->remove($toRemove);
Defensive patterns

Strategy: validation

Validate before calling

// Filter the removal list to entries that actually exist.
$current = $importMapConfigReader->getEntries();
$toRemove = array_filter($packages, fn($n) => $current->has($n));
if ($toRemove) { $manager->remove($toRemove); }

Type guard

function packagesExist(ImportMapEntries $entries, array $names): bool {
    foreach ($names as $n) { if (!$entries->has($n)) return false; }
    return true;
}

Try / catch

try {
    $manager->remove($packages);
} catch (\InvalidArgumentException $e) {
    if (str_contains($e->getMessage(), 'was not found in')) {
        // recompute existing list, remove incrementally
    } else { throw $e; }
}

Prevention

When it happens

Trigger: 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().

Common situations: Trying to remove a package whose import name differs from its npm name; double-removal; CI script removes a list including already-removed packages.

Related errors


AI-assisted analysis of symfony/symfony@698e28026c (2026-08-06). Data as JSON: /api/errors/e765bdc87654e818. Report an issue: GitHub.