为啥我会收到 Laravel Composer 解析错误?

Posted

技术标签:

【中文标题】为啥我会收到 Laravel Composer 解析错误?【英文标题】:Why do I get a Laravel Composer Parsing Error?为什么我会收到 Laravel Composer 解析错误? 【发布时间】:2016-11-15 21:58:53 【问题描述】:

我在 Laravel 的 composer.json 文件中收到以下错误...

错误:第 10 行的解析错误: ...l": "~2016.04", , "require-dev"

----------^

期待“字符串”

composer.json


    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": 
        "php": ">=5.5.9",
        "laravel/framework": "5.2.*",
        "aimeos/aimeos-laravel": "~2016.04",
    ,
    "require-dev": 
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~4.0",
        "symfony/css-selector": "2.8.*|3.0.*",
        "symfony/dom-crawler": "2.8.*|3.0.*",
    ,
    "autoload": 
        "classmap": [
            "database"
        ],
        "psr-4": 
            "App\\": "app/"
        
    ,
    "autoload-dev": 
        "classmap": [
            "tests/TestCase.php"
        ]
    ,
    "scripts": 
        "post-root-package-install": [
            "php -r \"copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ],
        "post-install-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postInstall",
            "php artisan optimize"
        ],
        "post-update-cmd": [
        "php artisan vendor:publish --tag=public --force",
            "php artisan vendor:publish",
            "php artisan migrate",
            "Illuminate\\Foundation\\ComposerScripts::postUpdate",
            "php artisan optimize"
        ]
    ,
    "config": 
        "preferred-install": "dist"
    
 

【问题讨论】:

【参考方案1】:

您应该删除最后一行的 , 并更好地练习使用 CMD 命令 这对您来说很容易。当您使用 cmd 时,它总是下载最新版本,并且 composer.json

中没有错误
composer require aimeos/aimeos-laravel

【讨论】:

【参考方案2】:

请不要在最后一个对象的末尾使用“,”,它告诉作曲家在此之后还有另一个字符串,作曲家没有找到任何其他字符串。所以你会遇到这种类型的错误...

删除那个逗号和愉快的编码..

【讨论】:

【参考方案3】:

JSON 对象或数组中不能有尾随逗号,您需要从以下行中删除它们

"aimeos/aimeos-laravel": "~2016.04",

"symfony/dom-crawler": "2.8.*|3.0.*",

【讨论】:

【参考方案4】:

您应该删除每个数组末尾的最后一个逗号。


    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": 
        "php": ">=5.5.9",
        "laravel/framework": "5.2.*",
    "aimeos/aimeos-laravel": "~2016.04"
    ,
    "require-dev": 
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~4.0",
        "symfony/css-selector": "2.8.*|3.0.*",
        "symfony/dom-crawler": "2.8.*|3.0.*"
    ,
    "autoload": 
        "classmap": [
            "database"
        ],
        "psr-4": 
            "App\\": "app/"
        
    ,
    "autoload-dev": 
        "classmap": [
            "tests/TestCase.php"
        ]
    ,
    "scripts": 
        "post-root-package-install": [
            "php -r \"copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ],
        "post-install-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postInstall",
            "php artisan optimize"
        ],
        "post-update-cmd": [
        "php artisan vendor:publish --tag=public --force",
            "php artisan vendor:publish",
            "php artisan migrate",
            "Illuminate\\Foundation\\ComposerScripts::postUpdate",
            "php artisan optimize"
        ]
    ,
    "config": 
        "preferred-install": "dist"
    
 

【讨论】:

以上是关于为啥我会收到 Laravel Composer 解析错误?的主要内容,如果未能解决你的问题,请参考以下文章

我收到此错误 /myproject/vendor/composer/../../App/Http/helpers.php Laravel

在没有 Composer 的情况下安装 Laravel

为 Laravel 安装 composer 时缺少 composer.json 文件

Composer 在安装 Laravel 时显示错误

laravel composer update 内存不足

为啥我得到一个 404 到 laravel 5.7 公共子文件夹?