symfony5 - 如何修复未找到命令“encore”。尝试在 symfony 中添加 css 时?
问题描述
只需按照说明进行操作:
https://symfony.com/doc/current/frontend/encore/installation.html
docker-compose exec php composer require symfony/webpack-encore-bundle
Xdebug: [Step Debug] Could not connect to debugging client. Tried: host.docker.internal:9003 (fallback through xdebug.client_host/xdebug.client_port) :-(
Using version ^1.12 for symfony/webpack-encore-bundle
./composer.json has been updated
Running composer update symfony/webpack-encore-bundle
Loading composer repositories with package information
Updating dependencies
Lock file operations: 1 install, 0 updates, 0 removals
- Locking symfony/webpack-encore-bundle (v1.12.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Nothing to install, update or remove
Generating optimized autoload files
composer/package-versions-deprecated: Generating version class...
composer/package-versions-deprecated: ...done generating version class
111 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
Run composer recipes at any time to see the status of your Symfony recipes.
Executing script cache:clear [OK]
Executing script assets:install public [OK]
Nothing to unpack
yarn install
yarn install v1.22.11
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
Done in 0.04s.
如果您使用 Symfony Flex,这将安装并启用 WebpackEncoreBundle,创建 assets/ 目录,添加 webpack.config.js 文件,并将 node_modules/ 添加到 .gitignore。您可以跳过本文的其余部分,通过阅读 Encore:设置您的项目来编写您的第一个 JavaScript 和 CSS!
我没有关闭 flex,所以它应该安装这些文件,但它没有。它只向 composer.json 添加了 encore 包,更新了 composer.lock ,创建了 .yarn-integrity
{
"systemParams": "linux-x64-59",
"modulesFolders": [
"node_modules"
],
"flags": [],
"linkedModules": [],
"topLevelPatterns": [],
"lockfileEntries": {},
"files": [],
"artifacts": {}
}
和纱线锁:
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
当我运行作曲家食谱时:
docker-compose exec php composer recipes
Xdebug: [Step Debug] Could not connect to debugging client. Tried: host.docker.internal:9003 (fallback through xdebug.client_host/xdebug.client_port) :-(
Available recipes.
* doctrine/annotations
* doctrine/doctrine-bundle
* doctrine/doctrine-migrations-bundle
* phpunit/phpunit
* sensio/framework-extra-bundle
* symfony/console
* symfony/debug-bundle
* symfony/flex
* symfony/framework-bundle
* symfony/mailer
* symfony/maker-bundle
* symfony/monolog-bundle
* symfony/notifier
* symfony/phpunit-bridge
* symfony/routing
* symfony/security-bundle
* symfony/translation
* symfony/twig-bundle
* symfony/validator
* symfony/web-profiler-bundle
* symfony/webpack-encore-bundle (recipe not installed)
* twig/extra-bundle
Run:
* composer recipes vendor/package to see details about a recipe.
* composer recipes:install vendor/package --force -v to update that recipe.
然后我跑
docker-compose exec php composer recipes:install symfony/webpack-encore-bundle
Xdebug: [Step Debug] Could not connect to debugging client. Tried: host.docker.internal:9003 (fallback through xdebug.client_host/xdebug.client_port) :-(
Run command with -v to see more details
Symfony operations: 1 recipe (795220943d71c24e78b567cea3978461)
- Configuring symfony/webpack-encore-bundle (>=1.9): From github.com/symfony/recipes:master
安装了 Webpack 配置和各种文件。但是 node_modules 仍然只有 .yarn-integrity file 。
运行这个,我得到错误:
yarn encore dev
yarn run v1.22.11
error Command "encore" not found.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
我错过了什么?或者它是程序/文档中的错误?
更新
试过:
yarn add --dev @symfony/webpack-encore
得到:
在“npm”注册表中找不到包“@symfony/stimulus-bridge”
如果我使用纱线,为什么它甚至会搜索 npm 注册表?
更新 2
你不是通过npm包管理器安装yarn的吗?如果没有,我建议你这样做。npm install --global 纱线
我不记得我是如何安装纱线的,也不知道如何检查。试过:
npm install --global yarn
> yarn@1.22.11 preinstall /home/darius/.nvm/versions/node/v9.11.2/lib/node_modules/yarn
> :; (node ./preinstall.js > /dev/null 2>&1 || true)
/home/darius/.nvm/versions/node/v9.11.2/bin/yarn -> /home/darius/.nvm/versions/node/v9.11.2/lib/node_modules/yarn/bin/yarn.js
/home/darius/.nvm/versions/node/v9.11.2/bin/yarnpkg -> /home/darius/.nvm/versions/node/v9.11.2/lib/node_modules/yarn/bin/yarn.js
+ yarn@1.22.11
updated 1 package in 0.497s
然后又
yarn add --dev @symfony/webpack-encore
yarn add v1.22.11
[1/4] Resolving packages...
⠄ @symfony/stimulus-bridge@^2.0.0
error Couldn't find package "@symfony/stimulus-bridge" on the "npm" registry.
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
更新 3
是的,我正在混合命令——一些从 docker 运行,一些从主机运行。Yarn 我从主机运行,因为我还不知道如何在 docker 上安装,我尝试过,但没有成功。我使用来自主机的纱线、npm 有那么糟糕吗?
您可以在 docker-compose.yml 中看到卷信息:
version: "3"
services:
php:
build: docker/php
volumes:
- .:/app:cached
# for xdebug
- ./docker/php/conf.d/xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
# - ./docker/php/conf.d/error_reporting.ini:/usr/local/etc/php/conf.d/error_reporting.ini
# end for xdebug
working_dir: /app
container_name: margin_php
depends_on:
- mysql
nginx:
image: nginx:1.15.0
ports:
- 127.0.0.1:${NGINX_PORT}:80
volumes:
- .:/app:cached
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:cached
container_name: margin_nginx
depends_on:
- php
mysql:
image: mysql:8.0
volumes:
- ./docker/mysql/data:/var/lib/mysql
ports:
- 127.0.0.1:${MYSQL_PORT}:3306
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DB_NAME: ${MYSQL_DB_NAME}
container_name: margin_mysql
解决方案
试试这个命令 yarn add --dev @symfony/webpack-encore –</p>
还可以从 npm 包管理器安装 yarn。npm install --global 纱线