Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nekooee's avatar

htmlspecialchars(): Argument #1 ($string) must be of type string, array given

I used Laravel 9 with Vite. I run yarn run build in server and build complete. but get this error:

TypeError
htmlspecialchars(): Argument #1 ($string) must be of type string, array given

Screen Shot

composer.json:

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^8.0",
        "ext-json": "*",
        "astrotomic/laravel-translatable": "^11.9",
        "cviebrock/eloquent-sluggable": "^9.0",
        "fruitcake/laravel-cors": "^2.0",
        "guzzlehttp/guzzle": "^7.0.1",
        "inertiajs/inertia-laravel": "^0.6.3",
        "intervention/image": "^2.5",
        "kavenegar/php": "^1.2",
        "laravel/framework": "9.19.0",
        "laravel/jetstream": "^2.1",
        "laravel/sanctum": "^2.6",
        "laravel/tinker": "^2.5",
        "spatie/laravel-permission": "^5.5.5",
        "tightenco/ziggy": "^1.4"
    },
    "require-dev": {
        "barryvdh/laravel-debugbar": "^3.6",
        "fakerphp/faker": "^1.9.1",
        "laravel/breeze": "^1.10",
        "laravel/sail": "^1.0.1",
        "mockery/mockery": "^1.4.2",
        "nunomaduro/collision": "^6.1",
        "phpunit/phpunit": "^9.3.3",
        "spatie/laravel-ignition": "^1.0"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "autoload": {
        "psr-4": {
            "App\": "app/",
            "Database\Factories\": "database/factories/",
            "Database\Seeders\": "database/seeders/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\": "tests/"
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\Foundation\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    }
}

package.json:

{
    "private": true,
    "scripts": {
        "dev": "vite",
        "build": "vite build"
    },
    "devDependencies": {
        "@mdi/font": "7.0.96",
        "@tailwindcss/aspect-ratio": "^0.4.0",
        "@tailwindcss/forms": "^0.5.2",
        "@tailwindcss/line-clamp": "^0.4.0",
        "@tailwindcss/typography": "^0.5.0",
        "@vitejs/plugin-vue": "3.0.1",
        "@vue/compiler-sfc": "^3.2.37",
        "alpinejs": "3.10.3",
        "autoprefixer": "^10.4.2",
        "axios": "^0.27.2",
        "laravel-vite-plugin": "0.5.2",
        "lodash": "^4.17.19",
        "postcss": "^8.4.6",
        "postcss-import": "^14.0.0",
        "sass": "1.54.0",
        "tailwindcss": "^3.1.0",
        "tailwindcss-rtl": "^0.9.0",
        "typescript": "^4.7.4",
        "video.js": "7.20.1",
        "vite": "3.0.4",
        "vite-plugin-dynamic-import": "^1.0.0",
        "vite-plugin-fonts": "0.6.0",
        "vue": "^3.2.36",
        "vue-template-compiler": "2.7.8"
    },
    "dependencies": {
        "@iconify/iconify": "^2.2.1",
        "@inertiajs/inertia": "^0.11.0",
        "@inertiajs/inertia-vue3": "^0.6.0",
        "at.js": "^1.5.4",
        "express": "^4.18.1",
        "jquery": "^3.6.0",
        "jquery.caret": "^0.3.1",
        "lazysizes": "^5.3.2",
        "moment": "^2.29.1",
        "vue-axios": "^3.4.1",
        "vue-country-flag-next": "^2.3.2",
        "vue-debounce": "^4.0.0",
        "vue-easy-dnd": "^1.22.0",
        "vue-meta": "^2.4.0",
        "vue-simple-progress": "^1.1.1",
        "vue-slider-component": "3.2.18",
        "vueperslides": "^3.4.2",
        "vuetify": "3.0.0-beta.5",
        "vuex": "^4.0.2"
    },
    "version": "0.0.0",
    "packageManager": "[email protected]"
}

vite config:

import {defineConfig} from 'vite';
import laravel from 'laravel-vite-plugin';
import vuePlugin from '@vitejs/plugin-vue';
import dynamicImport from 'vite-plugin-dynamic-import'
import { resolve } from "path";

export default defineConfig({
    plugins: [
        laravel([
            'resources/css/app.css',
            'resources/js/front.js',
            'resources/css/admin.css',
            'resources/js/admin.ts',
            'resources/js/app.ts',
        ]),
        {
            name: 'blade',
            handleHotUpdate({file, server}) {
                if (file.endsWith('.blade.php')) {
                    server.ws.send({
                        type: 'full-reload',
                        path: '*',
                    });
                }
            },
        },
        vuePlugin({
            template: {
                transformAssetUrls: {
                    base: null,
                    includeAbsolute: false,
                },
            },
        }),
        dynamicImport(/* options */)
    ],
    resolve: {
        alias: {
            "@": resolve(__dirname, "./resources/"),
            "@rsc": resolve(__dirname, "./resources"),
        }
    },
    server: {
        https: true,
    },
});
0 likes
8 replies
Sinnbeck's avatar

I have seen this happen when people have the other vite plug in installed. Try deleting your vendor folder and run composer update

1 like
nekooee's avatar
nekooee
OP
Best Answer
Level 1

@Sinnbeck Thanks. I had deleted the Vendor folder and run composer update before. But it was not fixed. Now I emptied the cache with the php artisan optimize:clear and fortunately the problem was solved.

Please or to participate in this conversation.