phalcon/cphalcon · error · Phalcon\Assets\Exceptions\InvalidAssetSourcePath
Asset '{path}' does not have a valid source path
Error message
Asset '{path}' does not have a valid source path What it means
While processing a filtered local asset the manager computes the real source path (base + asset path); if that comes back empty the manager reports the asset's own path in an InvalidAssetSourcePath exception. Empty here means the asset has no usable source location — typically the file does not exist so getRealSourcePath() yields nothing.
Source
Thrown at phalcon/Assets/Manager.zep:499
* If the collection must not be joined we must print a HTML for
* each one
*/
if (true !== empty(filters)) {
let sourcePath = asset->getPath();
if (true === asset->isLocal()) {
let filterNeeded = true;
/**
* Get the complete path
*/
let sourcePath = asset->getRealSourcePath(completeSourcePath);
/**
* We need a valid source path
*/
if (true === empty(sourcePath)) {
let sourcePath = asset->getPath();
throw new InvalidAssetSourcePath(sourcePath);
}
}
/**
* Get the target path, we need to write the filtered content to
* a file
*/
let targetPath = asset->getRealTargetPath(completeTargetPath);
/**
* We need a valid final target path
*/
if (true === empty(targetPath)) {
throw new InvalidAssetTargetPath(asset->getPath());
}
if (true === asset->isLocal()) {
/**View on GitHub (pinned to b7419de9cd)
Solutions
- Check the file exists: `var_dump(is_file($sourceBasePath . $asset->getPath()))` and fix the path or base
- Correct the Manager's 'sourceBasePath' option or the asset's path so the concatenation points at the real file
- Install the missing frontend dependencies before building assets
- Mark remote/CDN assets with `$asset->setLocal(false)` so no local read is attempted
Example fix
// before
$assets = new \Phalcon\Assets\Manager(['sourceBasePath' => '/app/public']);
$collection->addJs('/js/app.js', true, false); // resolves to /app/public/js/app.js which is missing
// after: deploy the file or fix the base
$assets = new \Phalcon\Assets\Manager(['sourceBasePath' => '/app/public']);
$collection->addJs('js/app.js', true, false); Defensive patterns
Strategy: validation
Validate before calling
$source = rtrim($sourceBasePath, '/') . '/' . ltrim($asset->getPath(), '/');
if (!is_file($source)) {
throw new RuntimeException('Cannot filter asset, source file missing: ' . $source);
}
echo $assets->outputJs($name); Try / catch
try {
echo $assets->outputJs('footer');
} catch (\Phalcon\Assets\Exceptions\InvalidAssetSourcePath $e) {
$logger->error('Asset source missing/unresolvable: ' . $e->getMessage());
echo $assets->outputJs(null); // degrade to unfiltered tags if acceptable
} Prevention
- Verify frontend dependencies (npm/bower assets) are installed before the asset build runs in CI
- Keep sourceBasePath in one config source and test it with a health check
- Use relative asset paths without a leading '/' to avoid double-joining with the base path
When it happens
Trigger: A filtered local asset whose file is missing at sourceBasePath . path when outputCss()/outputJs() runs; an asset constructed with an empty path; wrong 'sourceBasePath' so every lookup misses.
Common situations: Building CSS/JS in CI where bower/npm assets have not been fetched yet; wrong docroot base path in a Docker image; asset path starting with '/' that double-joins with the base path.
Related errors
- Path '{path}' is not a valid target path
- Path '{path}' is not a valid target path, it is a directory.
- Asset '{path}' does not have a valid target path
- The filter is not valid
- Annotations directory cannot be written
AI-assisted analysis of phalcon/cphalcon@b7419de9cd (2026-08-21).
Data as JSON: /api/errors/d58472f276c184b6.
Report an issue: GitHub.