【发布时间】:2019-11-18 21:29:35
【问题描述】:
我有一个奇怪的问题。 我使用 Symfony Flex,我在现有项目上工作。我尝试使用以下命令安装 webpack-encore-bundle:
composer require symfony/webpack-encore-bundle
然后我明白了:
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Restricting packages listed in "symfony/symfony" to "4.2.*"
Package operations: 1 install, 0 updates, 0 removals
- Installing symfony/webpack-encore-bundle (v1.6.2): Loading from cache
Package symfony/webpack-encore-pack is abandoned, you should avoid using it. Use symfony/webpack-encore-bundle instead.
Writing lock file
Generating autoload files
ocramius/package-versions: Generating version class...
ocramius/package-versions: ...done generating version class
Symfony operations: 1 recipe (8e557491367cda509fceebb187833635)
- Configuring symfony/webpack-encore-bundle (>=1.0): From github.com/symfony/recipes:master
Executing script cache:clear [OK]
Executing script assets:install --symlink --relative public [OK]
Some files may have been created or updated to configure your new packages.
Please review, edit and commit them: these files are yours.
然后我运行:
yarn install
我明白了:
yarn install v1.16.0
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.2.9: The platform "linux" is incompatible with this module.
info "fsevents@1.2.9" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning " > sass-loader@7.1.0" has unmet peer dependency "webpack@^3.0.0 || ^4.0.0".
[4/4] Building fresh packages...
success Saved lockfile.
Done in 2.39s.
一切似乎都很好。现在我刷新项目,我得到了这个:
ClassNotFoundException
Attempted to load class "WebpackEncoreBundle" from namespace "Symfony\WebpackEncoreBundle".
Did you forget a "use" statement for another namespace?
这就是我在 bundles.php 中的内容:
Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true],
在 composer.json 我有:
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
我跑:
yarn encore dev
它编译成功,但我有同样的错误。
我也试过这个命令:
composer remove symfony/webpack-encore-bundle
那我再试一次
composer require symfony/webpack-encore-bundle
然后我们遇到了同样的错误,这个循环永远不会结束。
【问题讨论】:
-
查看安装指南时,我没有看到您需要将捆绑包添加到 bundles.php。尝试删除它。 symfony.com/doc/current/frontend/encore/installation.html
-
它是由 Symfony Flex 自动添加的。
标签: php symfony webpack webpack-encore