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

jameskenny115's avatar

Laravel: Parse error: syntax error, unexpected '|', expecting variable

Getting a rather annoying error, running PHP 8.1 with a fresh install of Laravel 10 but this keeps appearing even though the all packages are up to date with no conflicts. Any help would be greatly appreciated!

Parse error: syntax error, unexpected '|', expecting variable (T_VARIABLE) in app/vendor/nunomaduro/termwind/src/Functions.php on line 17

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The skeleton application for the Laravel framework.",
    "keywords": ["laravel", "framework"],
    "license": "MIT",
    "require": {
        "php": "^8.1",
        "guzzlehttp/guzzle": "^7.2",
        "laravel/framework": "^10.10",
        "laravel/sanctum": "^3.2",
        "laravel/tinker": "^2.8"
    },
    "require-dev": {
        "fakerphp/faker": "^1.9.1",
        "laravel/pint": "^1.0",
        "laravel/sail": "^1.18",
        "mockery/mockery": "^1.4.4",
        "nunomaduro/termwind": "^1.15",
        "phpunit/phpunit": "^10.1",
        "spatie/laravel-ignition": "^2.0"
    },
    "autoload": {
        "psr-4": {
            "App\": "app/",
            "Database\Factories\": "database/factories/",
            "Database\Seeders\": "database/seeders/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\": "tests/"
        }
    },
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\Foundation\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-update-cmd": [
            "@php artisan vendor:publish --tag=laravel-assets --ansi --force"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true,
        "platform-check": false,
        "allow-plugins": {
            "pestphp/pest-plugin": true,
            "php-http/discovery": true
        }
    },
    "minimum-stability": "stable",
    "prefer-stable": true
}
0 likes
10 replies
PovilasKorop's avatar

Seems like you're running older PHP version. Please double check if you're really on PHP 8.1, both on web page and CLI.

jameskenny115's avatar

@PovilasKorop Yes I have, it was the first thing I checked. I was running 8.1 on both, now running 8.0 but the error persists.

PovilasKorop's avatar

@jameskenny115 very weird, as this error has no other explanation than PHP version. That's the ONLY possible reason for such syntax error.

Maybe some kind of caching? Try "composer dump-autoload"?

jameskenny115's avatar

@PovilasKorop haha yeah I know, it's very strange. Going to have to try a complete reinstall of everything at this rate! Yeah tried that as well 😂

Snapey's avatar

@jameskenny115 have you tried a composer update incase there was a temporary issue with a specific package?

Please or to participate in this conversation.