如何处理pentatrion中的renderTags()返回

问题描述 投票:0回答:1

我使用 pentatrion 将 vite 安装到我的 symfony 项目中。我按照 pentatrion 文档中的步骤进行操作(https://symfony-vite.pentatrion.com/extra/migration.html),但我仍然收到此错误:

Return value of Pentatrion\ViteBundle\Service\EntrypointRenderer::renderTags() must be an instance of Pentatrion\ViteBundle\Service\mixed, string returned

这是我日志中的错误:

[2024-06-20T22:39:48.201801+02:00] php.CRITICAL: Uncaught Error: Return value of Pentatrion\ViteBundle\Service\EntrypointRenderer::renderTags() must be an instance of Pentatrion\ViteBundle\Service\mixed, string returned {"exception":"[object] (TypeError(code: 0): Return value of Pentatrion\\ViteBundle\\Service\\EntrypointRenderer::renderTags() must be an instance of Pentatrion\\ViteBundle\\Service\\mixed, string returned at /.../myapp/vendor/pentatrion/vite-bundle/src/Service/EntrypointRenderer.php:289)"} []
[2024-06-20T22:39:48.303733+02:00] request.CRITICAL: Uncaught PHP Exception TypeError: "Return value of Pentatrion\ViteBundle\Service\EntrypointRenderer::renderTags() must be an instance of Pentatrion\ViteBundle\Service\mixed, string returned" at /.../myapp/vendor/pentatrion/vite-bundle/src/Service/EntrypointRenderer.php line 289 {"exception":"[object] (TypeError(code: 0): Return value of Pentatrion\\ViteBundle\\Service\\EntrypointRenderer::renderTags() must be an instance of Pentatrion\\ViteBundle\\Service\\mixed, string returned at /.../myapp/vendor/pentatrion/vite-bundle/src/Service/EntrypointRenderer.php:289)"} []

这是EntrypointRenderer.php中的函数:

/**
 * @return string|array
 */
public function renderTags(array $tags, bool $isBuild, bool $toString): mixed
{
    if (null !== $this->eventDispatcher) {
        foreach ($tags as $tag) {
            $this->eventDispatcher->dispatch(new RenderAssetTagEvent($isBuild, $tag));
        }
    }

    if ('link-tag' !== $this->preload) {
        $tags = array_filter($tags, function (Tag $tag) {
            return !$tag->isModulePreload();
        });
    }

    return $toString
    ? implode('', array_map(function ($tagEvent) {
        return TagRenderer::generateTag($tagEvent);
    }, $tags))
    : $tags; // line 289
}

这是版本:

"pentatrion/vite-bundle": "^6.3",

{
        "name": "pentatrion/vite-bundle",
        "version": "v6.3.4",
        "source": {
            "type": "git",
            "url": "https://github.com/lhapaipai/vite-bundle.git",
            "reference": "c46fa23e33064e087d178d79be9f117b411fff0c"
        },
        "dist": {
            "type": "zip",
            "url": "https://api.github.com/repos/lhapaipai/vite-bundle/zipball/c46fa23e33064e087d178d79be9f117b411fff0c",
            "reference": "c46fa23e33064e087d178d79be9f117b411fff0c",
            "shasum": ""
        },
        "require": {
            "php": "^7.4 || ^8.0",
            "symfony/asset": "^4.4 || ^5.0 || ^6.0 || ^7.0",
            "symfony/config": "^4.4 || ^5.0 || ^6.0 || ^7.0",
            "symfony/dependency-injection": "^4.4 || ^5.0 || ^6.0 || ^7.0",
            "symfony/framework-bundle": "^4.4 || ^5.0 || ^6.0 || ^7.0",
            "symfony/http-client": "^4.4 || ^5.0 || ^6.0 || ^7.0",
            "symfony/http-kernel": "^4.4 || ^5.0 || ^6.0 || ^7.0",
            "symfony/twig-bundle": "^4.4 || ^5.0 || ^6.0 || ^7.0"
        },
        "require-dev": {
            "friendsofphp/php-cs-fixer": "^3.9",
            "phpstan/phpstan": "^1.8",
            "phpunit/phpunit": "^9.5",
            "symfony/phpunit-bridge": "^4.4 || ^5.0 || ^6.0 || ^7.0",
            "symfony/web-link": "^4.4 || ^5.0 || ^6.0 || ^7.0"
        },
        "type": "symfony-bundle",
        "autoload": {
            "psr-4": {
                "Pentatrion\\ViteBundle\\": "src/"
            }
        },
        "notification-url": "https://packagist.org/downloads/",
        "license": [
            "MIT"
        ],
        "authors": [
            {
                "name": "Hugues Tavernier",
                "email": "[email protected]"
            }
        ],
        "description": "Vite integration for your Symfony app",
        "keywords": [
            "bundle",
            "symfony",
            "vite",
            "vitejs"
        ],
        "support": {
            "issues": "https://github.com/lhapaipai/vite-bundle/issues",
            "source": "https://github.com/lhapaipai/vite-bundle/tree/v6.3.4"
        },
        "time": "2024-01-25T22:11:09+00:00"
    }

树枝:

    <!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>{% block title %}Welcome!{% endblock %}</title>
        <link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 128 128%22><text y=%221.2em%22 font-size=%2296%22>⚫️</text></svg>">
        {% block stylesheets %}
            {{ vite_entry_link_tags('app') }}
        {% endblock %}
        
        <link rel="preconnect" href="https://fonts.googleapis.com">
        <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
        <link href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,500;1,600;1,700&display=swap" rel="stylesheet">

    </head>
    <body>
        {% block body %}{% endblock %}
        {% block javascripts %}
            {{ vite_entry_script_tags('app') }}
        {% endblock %}
        
    </body>
</html>

截图: Error symfony

Error

php symfony vite
1个回答
0
投票

这是包

pentatrion/vite-bundle
(在 v6.0.0 中引入,请参阅 https://github.com/lhapaipai/vite-bundle/pull/75)和 PHP 7 之间的不兼容。
mixed
作为返回类型是PHP 8 中引入,使用较旧的 PHP 版本运行代码会引发给定的错误。


您有两个选择:如果您确实需要坚持使用 PHP 7(不推荐,因为对该版本的各种支持已于 2022 年 11 月结束),您可以在 v5 中使用

pentatrion/vite-bundle
。请记住,这也可能会限制应用程序的进一步更新,例如,如果您想使用 Symfony 7。更好的想法是将 PHP 升级到 v8,但这也可能意味着应用程序的某些其他部分需要更新

© www.soinside.com 2019 - 2024. All rights reserved.