symfony / recipes

Symfony Recipes Repository
https://github.com/symfony/recipes/blob/flex/main/RECIPES.md
MIT License
953 stars 472 forks source link

[symfony/webpack-encore-bundle] [symfony/webapp-pack] Collision in creation of assets/bootstrap.js leading to corrupt file #1309

Open msmuenchen opened 2 months ago

msmuenchen commented 2 months ago

When installing both symfony/webapp-pack and symfony/webpack-encore-bundle simultaneously, the resulting assets/bootstrap.js file is corrupt:

import { startStimulusApp } from '@symfony/stimulus-bundle';

const app = startStimulusApp();
import { startStimulusApp } from '@symfony/stimulus-bridge';

// Registers Stimulus controllers from controllers.json and in the controllers/ directory
export const app = startStimulusApp(require.context(
    '@symfony/stimulus-bridge/lazy-controller-loader!./controllers',
    true,
    /\.[jt]sx?$/
));
// register any custom, 3rd party controllers here
// app.register('some_controller_name', SomeImportedController);

Attempting to compile that yields an error:

Syntax Error: Identifier 'startStimulusApp' has already been declared. (4:9)

  2 |
  3 | const app = startStimulusApp();
> 4 | import { startStimulusApp } from '@symfony/stimulus-bridge';

This should not happen in the first place given that

It should be noted that installing the webapp pack first and then installing webpack-encore-bundle directly afterwards works, I assume that something in the Composer interface is broken and doesn't recognize that both bundles are being installed?

Possibly it's also related to this issue, where stimulus got (finally) removed - but again, that shouldn't be the case since webpack-encore-bundle is clearly the newer version that shouldn't ship with stimulus?

Logs from composer require

  - Locking symfony/stimulus-bundle (v2.17.0)
  - Locking symfony/webapp-pack (v1.3.0)
  - Locking symfony/webpack-encore-bundle (v2.1.1)
...
  - Installing symfony/stimulus-bundle (v2.17.0): Extracting archive
  - Installing symfony/webapp-pack (v1.3.0): Extracting archive
  - Installing symfony/webpack-encore-bundle (v2.1.1): Extracting archive
...
  - Configuring symfony/stimulus-bundle (>=2.13): From github.com/symfony/recipes:main
  - Configuring symfony/webpack-encore-bundle (>=2.0): From github.com/symfony/recipes:main

Reproduce

Environment:

Composer version 2.7.4 2024-04-22 21:17:03
PHP version 8.3.6 (/opt/local/bin/php83)
  1. Create an empty skeleton project: composer create-project symfony/skeleton:"7.0.*" my_project_directory
  2. Install both the webapp pack and webpack-encore-bundle at the same time: cd my_project_directory && composer require symfony/webapp-pack symfony/webpack-encore-bundle
  3. Check content: cat assets/bootstrap.js