0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

miriwoお一人様Advent Calendar 2023

Day 4

laravel 8でlaravel newしたアプリを10に上げたらcomposer installでエラー発生

Last updated at Posted at 2023-12-03

概要

  • laravel8でlaravel newして作成したアプリをlaravel10に上げ、composer installを実行したところエラーが出たので解決方法を簡単にまとめる。

エラー内容

composer install

Deprecated: PHP Startup: Use of mbstring.internal_encoding is deprecated in Unknown on line 0
No composer.lock file present. Updating dependencies to latest instead of installing from lock file. See https://getcomposer.org/install for more information.
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires fruitcake/laravel-cors ^4.0, found fruitcake/laravel-cors[dev-feat-lazyoptions, dev-feat-groupmiddleware, dev-test-single, dev-feat-middlewaretest, dev-feat-actions, dev-feat-browsertests, dev-master, dev-v1-backport, dev-feat-prependmiddleware, dev-develop, dev-barryvdh-test-laravel9, dev-barryvdh-deprecate, v0.1, ..., 0.11.x-dev, v1.0.0, ..., 1.0.x-dev, v2.0.0-beta1, ..., 2.2.x-dev, v3.0.0, 3.0.x-dev (alias of dev-master)] but it does not match the constraint.
  Problem 2
    - Conclusion: don't install laravel/framework v10.0.0 (conflict analysis result)
    - Conclusion: don't install laravel/framework v10.0.1 (conflict analysis result)

どうやらcomposer.jsonでrequiredされているfruitcake/laravel-corsがlaravel10との関係で良くないことが起きてるっぽい。

解決策

ちょっと調べたら下記の知見が出てきた。

readme.mdの「Steps to upgrade:」の手順に沿えば解決できそう。

Remove "fruitcake/laravel-cors" from your composer.json
Replace \Fruitcake\Cors\HandleCors::class, with \Illuminate\Http\Middleware\HandleCors::class, in app/Http/Kernel.php

取り急ぎcomposer.jsonからfruitcake/laravel-corsの記述を削除すればいいらしい。その後、コードの変更も必須らしい。

指示された通りにcomposer.jsonからfruitcake/laravel-corsを削除してcomposer installを実行する。

他のエラーは出るが、当該のエラーはなくなった。

その他にもバージョン絡みによるエラーが出た(spatie/laravel-ignitionlaravel/sanctum)この辺も同様にhttps://packagist.org/ で最新バージョンを確認し、設定することでcomposer installを実行することができた。

composer installが終わってアプリケーションの画面を確認したところ下記のようにエラーが出た。Fruitcake\Cors\HandleCorsが見つからない旨のエラーだ。(当該パッケージをrequiredから削除したから当たり前である。)

Target class [Fruitcake\Cors\HandleCors] does not exist.

app/Http/Kernel.phpの当該の記載を下記のように修正した。

  • 修正前

    /**
     * The application's global HTTP middleware stack.
     *
     * These middleware are run during every request to your application.
     *
     * @var array<int, class-string|string>
     */
    protected $middleware = [
        // \App\Http\Middleware\TrustHosts::class,
        \App\Http\Middleware\TrustProxies::class,
        \Fruitcake\Cors\HandleCors::class,
        \App\Http\Middleware\PreventRequestsDuringMaintenance::class,
        \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
        \App\Http\Middleware\TrimStrings::class,
        \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
    ];
    
  • 修正後

    /**
     * The application's global HTTP middleware stack.
     *
     * These middleware are run during every request to your application.
     *
     * @var array<int, class-string|string>
     */
    protected $middleware = [
        // \App\Http\Middleware\TrustHosts::class,
        \App\Http\Middleware\TrustProxies::class,
        \Illuminate\Http\Middleware\HandleCors::class,
        \App\Http\Middleware\PreventRequestsDuringMaintenance::class,
        \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
        \App\Http\Middleware\TrimStrings::class,
        \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
    ];
    
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?