Skip to content

[StimulusBundle] Error with AssetMapper 6.4 & StimulusBundle #1210

@weaverryan

Description

@weaverryan

Originally from symfony/symfony#52106 (comment) from @tacman

The above require now works, thanks!

When I try to install asset-mapper:^6.4 in an existing project that's been upgraded to 6.4-DEV, I'm getting an error:

bash
composer req symfony/asset-mapper:^6.4

Symfony operations: 1 recipe (f9876b0bb3302355035a27b85d2368f3)
  - Configuring symfony/asset-mapper (>=6.4): From github.com/symfony/recipes:main
Executing script importmap:require [OK]
Executing script importmap:require [KO]
 [KO]
Script importmap:require returned with error code 1
!!  
!!  In ControllersMapGenerator.php line 75:
!!                                                         
!!    Warning: Attempt to read property "content" on null  
!!                                                         
!!  
!!  importmap:require [--entrypoint] [--path PATH] [--] <packages>...
!!  
!!  

The lines in question are

        foreach ($finder as $file) {
            $name = $file->getRelativePathname();
            $name = str_replace(['_controller.js', '-controller.js'], '', $name);
            $name = str_replace(['_', '/'], ['-', '--'], $name);

            $asset = $this->assetMapper->getAssetFromSourcePath($file->getRealPath());
            $isLazy = preg_match('/\/\*\s*stimulusFetch:\s*\'lazy\'\s*\*\//i', $asset->content);

            $controllersMap[$name] = new MappedControllerAsset($asset, $isLazy);
        }

so I suspect this has something to do with this project originally being in 6.3 and now being updated. Might it be possible to get a better message? $asset is null, and so maybe check for that and throw and error that includes the file->getRealPath().

The component installs okay, it's failing during the recipe, but I'm not sure what the full command is that the recipe is trying to run.

Executing script importmap:require [OK]

It would be helpful if the arguments were in this debug line, so I could isolate the problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugBug Fix

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions