phalcon/cphalcon · error · Phalcon\Assets\Exceptions\InvalidAssetTargetPath

Asset '{path}' does not have a valid target path

Error message

Asset '{path}' does not have a valid target path

What it means

Symmetric to the source-path check: for a filtered asset the manager computes the real target path (target base + asset targetPath); if it is empty there is nowhere to write the filtered result, and InvalidAssetTargetPath is thrown with the asset's own path in the message.

Source

Thrown at phalcon/Assets/Manager.zep:513

                     */
                    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()) {
                    /**
                     * Make sure the target path is not the same source path
                     */
                    if (targetPath === sourcePath) {
                        throw new AssetSourceTargetCollision(targetPath);
                    }

                    if (true === this->phpFileExists(targetPath)) {
                        if (filemtime(targetPath) !== filemtime(sourcePath)) {
                            let filterNeeded = true;
                        }
                    } else {
                        let filterNeeded = true;
                    }
                }

View on GitHub (pinned to b7419de9cd)

Solutions

  1. Set an output file per asset: `$asset->setTargetPath('js/app.min.js')`
  2. Or set it once for the collection: `$collection->setTargetPath('js/build/')` plus a Manager 'targetBasePath'
  3. Drop the filter if no transformation is needed, avoiding the disk write entirely

Example fix

// before
$collection->addJs('js/app.js')->addFilter(new \Phalcon\Assets\Filters\Jsmin());
// after
$collection->addJs('js/app.js')
    ->setTargetPath('js/app.min.js')
    ->addFilter(new \Phalcon\Assets\Filters\Jsmin());
Defensive patterns

Strategy: validation

Validate before calling

foreach ($collection->getAssets() as $asset) {
    if ('' === trim((string) $asset->getTargetPath())) {
        throw new RuntimeException('Filtered asset lacks targetPath: ' . $asset->getPath());
    }
}
echo $assets->outputJs($name);

Try / catch

try {
    echo $assets->outputJs('footer');
} catch (\Phalcon\Assets\Exceptions\InvalidAssetTargetPath $e) {
    $logger->error('Filtered asset has no target path: ' . $e->getMessage());
    throw $e;
}

Prevention

When it happens

Trigger: A filtered local asset without a targetPath (and no global 'targetBasePath' option) during outputCss()/outputJs(); collections where only some assets received setTargetPath().

Common situations: Adding filters to an existing unfiltered asset list and forgetting output paths; relying on collection-level targetPath while filtering individual assets of a non-joined collection; missing 'targetBasePath' in Manager options.

Related errors


AI-assisted analysis of phalcon/cphalcon@b7419de9cd (2026-08-21). Data as JSON: /api/errors/36bacc935f5cfa27. Report an issue: GitHub.