Skip to content

Component discovery fails with symlinked packages outside project directory #575

@prof-anderson-trindade

Description

@prof-anderson-trindade

Component discovery fails with symlinked packages outside project directory

Description

When using Composer path repositories with symlinks pointing to packages outside the project directory, the extension fails to discover Blade components with a file_get_contents error.

Error Message

ErrorException

file_get_contents(C:\laragon6\www\cegrad3beta\C:\laragon6\www\packages\laravel-layout-system\resources\views\components\content\page-header.blade.php): Failed to open stream: No such file or directory

at vendor\_laravel_ide\discover-*.php:418
    protected function parseProps($compiler, array $component): ?string
    {
        $content = file_get_contents(base_path($component['path']));

Root Cause

The issue is in the parseProps method at line 418 of the discovery script:

$content = file_get_contents(base_path($component['path']));

When a package is symlinked from outside the project (e.g., ../packages/laravel-layout-system), the component path is resolved to an absolute path:

C:\laragon6\www\packages\laravel-layout-system\resources\views\components\content\page-header.blade.php

Then base_path() prepends the project path, resulting in an invalid double path:

C:\laragon6\www\cegrad3beta\C:\laragon6\www\packages\laravel-layout-system\...

Suggested Fix

Check if the path is already absolute before calling base_path():

protected function parseProps($compiler, array $component): ?string
{
    $path = $component['path'];

    // Check if path is already absolute (Windows or Unix)
    $isAbsolute = preg_match('/^([a-zA-Z]:\\\\|\\/)/', $path);
    $fullPath = $isAbsolute ? $path : base_path($path);

    $content = file_get_contents($fullPath);
    // ...
}

Environment

  • Extension version: 1.5.1
  • OS: Windows 11
  • PHP Environment: Laravel Herd

composer.json (relevant part)

{
    "repositories": {
        "laravel-layout-system": {
            "type": "path",
            "url": "../packages/laravel-layout-system",
            "options": {
                "symlink": true
            }
        }
    }
}

Workaround

Disable Blade component features in .vscode/settings.json:

{
    "Laravel.bladeComponent.link": false,
    "Laravel.bladeComponent.completion": false,
    "Laravel.bladeComponent.hover": false
}

Steps to Reproduce

  1. Create a Laravel project
  2. Create a package outside the project directory with Blade components
  3. Add it as a Composer path repository with symlink
  4. Open the project in VS Code with the Laravel extension
  5. Observe the error in the Output panel (Laravel channel)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions