How to fix "https://repo.packagist.org/packages.json does not contain valid Json"?
Asked Answered
P

10

14

I've an issue with composer running on a vagrantbox (Centos 7), which started to just suddenly happen.

I've already tried manually running the command/solution mentioned on the link below but to no avail.

(To clarify, i'm using vagrant not docker, but it was the closest question i found to my situation. Most of the information i found are related to composer.json not being valid, but here is packagist.org/packages.json which, is currently valid)

Composer not working in docker container: "https://packagist.org/packages.json" does not contain valid JSON

Here are the details of the issue.

While running composer update on terminal i get:

 composer update


  [Seld\JsonLint\ParsingException]
  "https://repo.packagist.org/packages.json" does not contain valid JSON
  Parse error on line 1:

  ^
  Expected one of: 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '['

And when running composer install also on terminal every package returns this:

Failed to download psr/cache from dist: "https://api.github.com/repos/php-fig/cache/zipball/d11b50ad223250cf17b86e38383413f5a6764bf8" 
appears broken, and returned an empty 200 response
    Now trying to download from source

When running composer config --global repo.packagist composer packagist.org the results are now

composer update
Loading composer repositories with package information


  [Composer\Downloader\TransportException]
  Your configuration does not allow connections to http://repo.packagist.org/packages.json. See https://getcomposer.o
  rg/doc/06-config.md#secure-http for details.

Any ideas why this started to happen, how can i fix it?

Pesade answered 9/4, 2019 at 16:13 Comment(8)
this is a little bit confugins .. are you using docker or vagrant ? the command above which is "composer update" .. did you run it form terminal or is it inside dockerfile ? .. please add more detailsRosner
Updated and edited, hopefully its more clear now. Sorry about the confusionPesade
your vm has access to public ? can you ping google.com ?Rosner
Yes I can ping. If i actually perform the composer install, after the message i showed on the issue description it continues to download and install the packages, but takes a lot more time than with regular/normal behavior and shows that message for every single package. Composer update is a no go still after installing completesPesade
did you try solution there which is composer config --global repo.packagist composer packagist.orgRosner
Updated above with result of running that commandPesade
try to configure php.ini - -extension=php_openssl.dll ... and have a look here #38818964Rosner
Tried to configure php.ini on centos as that's where my php and composer run but no changes. But i've found that i'm able to run composer update while disabling https. It's a security risk but i'll mention it nevertheless. As it's mentioned here: https://mcmap.net/q/901878/-latest-composer-version-not-pulling-laravelPesade
G
6

same problem here, since php updated to 7.2.17. On a centos 7 with php 7.2.16 composer run just fine... Rollback to 7.2.16 is for now the only solution found...

Edit : Seems to be a symfony flex issue : https://github.com/symfony/flex/issues/484

Gravitate answered 11/4, 2019 at 9:54 Comment(2)
Thanks for the headsup! I'm on php 7.3 and as mentioned on that issue, it happened on that version too. I'm marking this question as resolved with your comment since it is now fixed in relation to the github issue you mention and its corresponding commit. Just reinstall your packages! (Note: Might have to delete vendor folder and composer.lock for a fresh install)Pesade
This answer inspired me. I got repo.packagist.org:443; Connection refused and repo.packagist.org:80; Connection refused errors, even 2001:41d0:801:1000::27d: Network is unreachable errors. Then I read your answer, found out we have PHP 7.1.29. I ran the composer diagnose via PHP 7.2.18 and 5.6.40, and it worked! This mystical issue finally solved!Sanbo
C
14

Could also be IPv6 related, if your provider/system is configured for IPv6 but has no valid IPv6 route out to the internet.

This happened to me, and doing sysctl -w net.ipv6.conf.all.disable_ipv6=1 (as root), then trying composer again fixed the issue.

To permanently apply it, add the rule to /etc/sysctl.conf (or wherever your OS preferred is)

Chancy answered 28/6, 2020 at 14:33 Comment(0)
G
6

same problem here, since php updated to 7.2.17. On a centos 7 with php 7.2.16 composer run just fine... Rollback to 7.2.16 is for now the only solution found...

Edit : Seems to be a symfony flex issue : https://github.com/symfony/flex/issues/484

Gravitate answered 11/4, 2019 at 9:54 Comment(2)
Thanks for the headsup! I'm on php 7.3 and as mentioned on that issue, it happened on that version too. I'm marking this question as resolved with your comment since it is now fixed in relation to the github issue you mention and its corresponding commit. Just reinstall your packages! (Note: Might have to delete vendor folder and composer.lock for a fresh install)Pesade
This answer inspired me. I got repo.packagist.org:443; Connection refused and repo.packagist.org:80; Connection refused errors, even 2001:41d0:801:1000::27d: Network is unreachable errors. Then I read your answer, found out we have PHP 7.1.29. I ran the composer diagnose via PHP 7.2.18 and 5.6.40, and it worked! This mystical issue finally solved!Sanbo
R
1

I had the same problem. After days of searching, I found a solution. It seems a PHP problem. Try to comment a line of curl extension on php.ini. I am using php version 5.6.

extension=php_curl.dll 

Type ; before the extension name, at least it will be like this:

;extension=php_curl.dll
Redundancy answered 9/12, 2020 at 22:51 Comment(0)
S
0

I had the same issue try to install symfony twig bundle. I ran :

set http_proxy=
set https_proxy=
composer require symfony/twig-bundle 

and it worked

Sinistral answered 13/10, 2021 at 8:10 Comment(0)
D
0

I ran a composer global require laravel/installer simply upgrading laravel/installer according to Laravel https://laravel.com/docs/9.x/installation#the-laravel-installer and the error was resolved.

Duron answered 26/6, 2022 at 14:5 Comment(0)
D
0

In my case, I just had to install the php-curl package, as suggested by composer diagnose.

Desuetude answered 31/1, 2024 at 11:57 Comment(0)
U
-1

Simply Just check out your internet and it well be ok

Use answered 22/10, 2022 at 7:52 Comment(1)
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewStpierre
P
-2
My solution: connect to a vpn before running the command!

For me basically the problem was because my IP was from Iran. Connected to a vpn and it worked perfectly.

Pia answered 11/6, 2022 at 7:36 Comment(0)
S
-4

it will works when we run this command in console

composer config disable-tls true
Station answered 29/11, 2019 at 12:7 Comment(1)
This is disabling a security feature, can't be considered a real solution to the original problemPesade
C
-7

I bypassed the problem by redirecting the output to /dev/null.

composer require symfony/orm-pack > /dev/null
Cornu answered 30/7, 2019 at 23:45 Comment(1)
That doesn't actually fix the problem, it just hides it.Hazlitt

© 2022 - 2025 — McMap. All rights reserved.