没有不值得去解决的问题,也没有不值得去学习的技术!

Build Composer Fails in GitLab CI/CD Pipelines

Building composer failed in the GitLab CI/CD Pipelines

1. Building composer failed in the GitLab CI/CD Pipelines. See Figure 1.

Building composer failed in the GitLab CI/CD Pipelines
Figure 1
Plaintext

$ php artisan key:generate

In DatabaseServiceProvider.php line 88:
                                   
  Class 'Faker\Factory' not found  
                                   

Cleaning up file based variables
ERROR: Job failed: command terminated with exit code 1

2. I searched for Class ‘Faker\Factory’ in the local environment and confirmed that /vendor/fzaninotto/faker/src/Faker/Factory.php exists. Running `php artisan key:generate` in the local environment succeeded. See Figure 2.

Searched for Class 'Faker\Factory' in the local environment and confirmed that /vendor/fzaninotto/faker/src/Faker/Factory.php exists. Running php artisan key:generate in the local environment succeeded
Figure 2
Plaintext

PS E:\wwwroot\object> php artisan key:generate
Application key set successfully.

3. I checked the logs in gitlab-runner: `if [ ! -x “vendor” ];then echo ‘vendor not exists’; composer self-update 2.1.14; composer install –prefer-dist –no-ansi –no-interaction –no-progress –no-scripts –no-dev; else echo ‘vendor exists’; fi`. See Figure 3.

Checking the logs in gitlab-runner
Figure 3
Plaintext

$ if [ ! -x "vendor" ];then echo 'vendor not exists'; composer self-update 2.1.14; composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts --no-dev; else echo 'vendor exists'; fi
vendor not exists
You are already using the latest available Composer version 2.1.14 (stable channel).
Installing dependencies from lock file
Verifying lock file contents can be installed on current platform.
Package operations: 233 installs, 0 updates, 0 removals

4. I ran `composer install –prefer-dist –no-ansi –no-interaction –no-progress –no-scripts –no-dev` in the local environment, and then ran `php artisan key:generate`. It threw an error: In Application.php line 679: Class ‘Barryvdh\Debugbar\ServiceProvider’ not found. The reason should be a difference in configuration between the local and production environments.

Plaintext

PS E:\wwwroot\object> php artisan key:generate

In Application.php line 679:

  Class 'Barryvdh\Debugbar\ServiceProvider' not found



5. I ran `composer install –prefer-dist –no-ansi –no-interaction –no-progress –no-scripts` in the local environment, and then ran `php artisan key:generate`. No error occurred this time. This confirmed that the pipeline failure was caused by adding the `–no-dev` option. `–no-dev`: skips packages listed in the require-dev section. In the require-dev configuration of composer.json, there is `”fzaninotto/faker”: “^1.4″`.

Plaintext

    "require-dev": {
        "fzaninotto/faker": "^1.4",
    },

6. I moved `”fzaninotto/faker”: “^1.4″` from the require-dev configuration to the require configuration. The error no longer occurred.

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系