{"record":{"id":"bc626d6e3f4b793c","repo":"symfony/symfony","slug":"unable-to-find-asset-s-imported-from-s-add","errorCode":null,"errorMessage":"Unable to find asset \"%s\" imported from \"%s\". Add it to \"importmap.php\", e.g. via the \"importmap:require\" command.","messagePattern":"Unable to find asset \"(.+?)\" imported from \"(.+?)\"\\. Add it to \"importmap\\.php\", e\\.g\\. via the \"importmap:require\" command\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Symfony/Component/AssetMapper/Compiler/JavaScriptImportPathCompiler.php","lineNumber":145,"sourceCode":"    {\n        return 'js' === $asset->publicExtension;\n    }\n\n    private function makeRelativeForJavaScript(string $path): string\n    {\n        if (str_starts_with($path, '../')) {\n            return $path;\n        }\n\n        return './'.$path;\n    }\n\n    private function handleMissingImport(string $message, ?\\Throwable $e = null): void\n    {\n        match ($this->missingImportMode) {\n            AssetCompilerInterface::MISSING_IMPORT_IGNORE => null,\n            AssetCompilerInterface::MISSING_IMPORT_WARN => $this->logger?->warning($message),\n            AssetCompilerInterface::MISSING_IMPORT_STRICT => throw new RuntimeException($message, 0, $e),\n        };\n    }\n\n    private function findAssetForBareImport(string $importedModule, MappedAsset $asset, AssetMapperInterface $assetMapper): ?MappedAsset\n    {\n        if (!$importMapEntry = $this->importMapConfigReader->findRootImportMapEntry($importedModule)) {\n            // Bare names may resolve to a valid URL at runtime, so we don't warn about them in general.\n            // But the browser can only load a CSS or JSON module by bare name through an importmap entry\n            // (the experimental import-attributes `with { type: '...' }` syntax aside), so a missing bare\n            // `.css`/`.json` import silently does nothing - warn the user at compile time.\n            if (!$asset->isVendor\n                && !str_contains($importedModule, '://')\n                && (str_ends_with($lowerModule = strtolower($importedModule), '.css') || str_ends_with($lowerModule, '.json'))\n            ) {\n                $this->handleMissingImport(\\sprintf('Unable to find asset \"%s\" imported from \"%s\". Add it to \"importmap.php\", e.g. via the \"importmap:require\" command.', $importedModule, $asset->sourcePath));\n            }\n\n            return null;","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/symfony/symfony/blob/3b11ffbe2520436b0951974d1993dc2144f91dd3/src/Symfony/Component/AssetMapper/Compiler/JavaScriptImportPathCompiler.php#L127-L163","documentation":"JavaScriptImportPathCompiler::findAssetForBareImport runs when a JS import uses a bare module specifier that is not in the root importmap. For bare specifiers ending in .css or .json, imported from a non-vendor asset and containing no '://', it calls handleMissingImport with this message, because a browser cannot resolve a bare CSS/JSON module without an importmap entry. In strict mode it throws RuntimeException.","triggerScenarios":"Source JS (not vendor) contains import './styles.css' resolved to a bare specifier like 'styles.css' (or import 'data.json') that has no importmap.php entry, with missing_import_mode=strict. The hint points to the importmap:require command.","commonSituations":"Adding a CSS/JSON module import without registering it in importmap.php; converting a bundler setup to AssetMapper and forgetting to port the dependency list.","solutions":["Register the module in importmap.php: 'php bin/console importmap:require styles.css'.","Convert the bare import to an explicit relative path that AssetMapper can map.","If the module is vendored, place it under the vendor path so it is treated as is_vendor."],"exampleFix":"// before\nimport './styles.css'; // resolved to bare specifier with no importmap entry\n// after\nphp bin/console importmap:require styles.css","handlingStrategy":"validation","validationCode":"// ensure bare css/json imports are in the importmap before strict compile\nforeach ($bareImports as $name) {\n    if (null === $importMapConfigReader->findRootImportMapEntry($name)) {\n        // register via importmap:require\n    }\n}","typeGuard":"function bareImportIsMapped(string $module, ImportMapConfigReader $reader): bool\n{\n    return null !== $reader->findRootImportMapEntry($module);\n}","tryCatchPattern":null,"preventionTips":["Register every bare module dependency with 'php bin/console importmap:require'.","Prefer relative imports for local modules so AssetMapper resolves them without importmap."],"tags":["asset-mapper","javascript","importmap","missing-import"],"backgroundTag":null,"analyzedSha":"3b11ffbe2520436b0951974d1993dc2144f91dd3","analyzedAt":"2026-08-11T22:13:02.001Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}