symfony/symfony · error · RuntimeException

Error %d requiring packages from jsDelivr for "%s". Check yo

Error message

Error %d requiring packages from jsDelivr for "%s". Check your package names. Response: {response_body}

What it means

Aggregated HTTP error raised after the package-content download round: one or more requests to `https://cdn.jsdelivr.net/npm/<pkg>@<version>.../+esm` (or the CSS variant) returned non-200, even though version resolution succeeded. The %d is the status code, %s the list of offending package specifiers, followed by the raw response body. Raised in the deferred error block at lines 126-133.

Source

Thrown at src/Symfony/Component/AssetMapper/ImportMap/Resolver/JsDelivrEsmResolver.php:132

            if (200 !== $response->getStatusCode()) {
                $getContentErrors[] = [$options->packageModuleSpecifier, $response];
                continue;
            }

            $contentType = $response->getHeaders()['content-type'][0] ?? '';
            $type = str_starts_with($contentType, 'text/css') ? ImportMapType::CSS : ImportMapType::JS;
            $resolvedPackages[$options->packageModuleSpecifier] = new ResolvedImportMapPackage($options, $version, $type);

            $packagesToRequire = array_merge($packagesToRequire, $this->fetchPackageRequirementsFromImports($response->getContent()));
        }

        try {
            ($getContentErrors[0][1] ?? null)?->getHeaders();
        } catch (HttpExceptionInterface $e) {
            $response = $e->getResponse();
            $packages = implode('", "', array_column($getContentErrors, 0));

            throw new RuntimeException(\sprintf('Error %d requiring packages from jsDelivr for "%s". Check your package names. Response: ', $response->getStatusCode(), $packages).$response->getContent(false), 0, $e);
        }

        // process any pending CSS entrypoints
        $entrypointErrors = [];
        foreach ($entrypointResponses as $package => [$cssEntrypointResponse, $version]) {
            if (200 !== $cssEntrypointResponse->getStatusCode()) {
                $entrypointErrors[] = [$package, $cssEntrypointResponse];
                continue;
            }

            $entrypoints = $cssEntrypointResponse->toArray()['entrypoints'] ?? [];
            $cssFile = $entrypoints['css']['file'] ?? null;
            $guessed = $entrypoints['css']['guessed'] ?? true;

            if (!$cssFile || $guessed) {
                continue;
            }

View on GitHub (pinned to 698e28026c)

Solutions

  1. Read the response body - it usually identifies whether the package, version, or path is wrong.
  2. Drop the explicit path and let the ESM build be used (remove the path, keep useEsm=true).
  3. Try a different version constraint, e.g. `^1` instead of `^2`, if the dist layout changed.
  4. Retry `importmap:install` after a short delay if you suspect CDN propagation.

Example fix

// before
return [
    'app' => ['path' => 'pkg/old/dist/index.js', 'version' => '^2'],
];

// after
return [
    'app' => ['path' => 'pkg', 'version' => '^2'], // use jsDelivr ESM build
];
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-validate the version+path resolves on jsDelivr CDN
use Symfony\Component\HttpClient\HttpClient;
$url = sprintf('https://cdn.jsdelivr.net/npm/%s@%s%s/+esm', $pkg, $version, $path);
$r = HttpClient::create()->request('GET', $url);
if (200 !== $r->getStatusCode()) {
    throw new \RuntimeException("Package content URL $url returned HTTP ".$r->getStatusCode());
}

Type guard

function packageContentFetchable(string $pkg, string $version, string $path, bool $esm): bool {
    $url = $esm
        ? sprintf('https://cdn.jsdelivr.net/npm/%s@%s%s/+esm', $pkg, $version, $path)
        : sprintf('https://cdn.jsdelivr.net/npm/%s@%s%s', $pkg, $version, $path);
    return 200 === \Symfony\Component\HttpClient\HttpClient::create()->request('GET', $url)->getStatusCode();
}

Try / catch

try {
    $resolver->resolvePackages($opts);
} catch (\Symfony\Component\AssetMapper\Exception\RuntimeException $e) {
    if (str_contains($e->getMessage(), 'requiring packages from jsDelivr')) {
        // drop explicit path, switch to ESM, or change version
    }
    throw $e;
}

Prevention

When it happens

Trigger: The resolved version exists but the specific dist path or `+esm` build is unavailable (e.g. 404 for a file that was removed in that version); `importmap:install` after a version resolution where the CDN has not yet propagated the build; transient 5xx on jsDelivr CDN; an explicit version pin pointing at a version whose main entry differs.

Common situations: Pinning a version that has a different dist layout than expected; requiring a package whose ESM build is not generated by jsDelivr; CDN propagation delay right after a package publish; specifying a path that does not exist in that version (e.g. `/dist/index.js` removed in v2).

Related errors


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