'Composer Json Validation Error for regex pattern ^[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9](([_.]?|-{0,2})[a-z0-9]+)*$

so i tried to install composer and laravel into Phpstorm, but right now there seems to be a problem installing the composer.json file in php. PHP version is 7.4.8. The error code is as shown below.

   "./composer.json" does not match the expected JSON schema:
    - name : Does not match the regex pattern ^[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9](([_.]?|-{0,2})[a-z0-9]+)*$

I tried to look it up for help but it didnt get me far enough, so I was wondering if anyone could help me out with this problem.

this is how my composer.json looked like.

{
  "name": "vendor_name/PhpProjec",
  "description": "description",
  "minimum-stability": "stable",
  "license": "proprietary",
  "authors": [
    {
      "name": "***",
      "email": "[email protected]"
    }
  ],
  "require": {
    "barryvdh/laravel-ide-helper": "v2.7.0"
  }


Solution 1:[1]

The problem is in the "name" property

- name : Does not match the regex pattern ^[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9](([_.]?|-{0,2})[a-z0-9]+)*$

Change the "name" property accordingly "vendor-name/project-name"

eg: "name": "nismi/my-php-project"

Solution 2:[2]

composer is case sensitive from v1.9 onwards... so change "PhpProject" to "phpproject"

   {
  "name": "vendor_name/phpproject",
  "description": "description",
  "minimum-stability": "stable",
  "license": "proprietary",
  "authors": [
    {
      "name": "***",
      "email": "[email protected]"
    }
  ],
  "require": {
    "barryvdh/laravel-ide-helper": "v2.7.0"
  }

Solution 3:[3]

Easy fix go to composer.json file find where is capitalizised e.g Izupay/PayMent to izupay/payment this will fix the error.

{
  "name": "IzuPay/PayMent",
  "description": "description",
  "minimum-stability": "stable",
  "license": "proprietary",
  "authors": [
    {
      "name": "***",
      "email": "[email protected]"
    }
  ],
  "require": {
    "barryvdh/laravel-ide-helper": "v2.7.0"
  }

Working answer is:

{
  "name": "izupay/payment",
  "description": "description",
  "minimum-stability": "stable",
  "license": "proprietary",
  "authors": [
    {
      "name": "***",
      "email": "[email protected]"
    }
  ],
  "require": {
    "barryvdh/laravel-ide-helper": "v2.7.0"
  }

Solution 4:[4]

This most likely has to do with the version of Composer you're using.

Before Composer version 2.0, a name could contain any character, including white spaces.

However, from version 2.0 upwards:

  • the name can consists of words separated by -, . or _.
  • the complete name should match ^a-z0-9/a-z0-9$.
  • the name must be lowercased (so instead of vendor_name/PhpProjec, it would be vendor_name/phpprojec

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nismi Mohamed
Solution 2 honglin zhang
Solution 3 bad_coder
Solution 4 JoshX