Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Composer generating empty .json files #3786

Closed
budde377 opened this Issue Feb 26, 2015 · 15 comments

Comments

Projects
None yet
8 participants
@budde377
Copy link

budde377 commented Feb 26, 2015

When running composer install it always results in an exception

  [Composer\Repository\InvalidRepositoryException]                                                                                                      
  Invalid repository data in /path/to/package/vendor/composer/installed.json, packages could not be loaded: [Seld\JsonLint\ParsingExcep  
  tion] "/path/to/package/vendor/composer/installed.json" does not contain valid JSON                                                    
  Parse error on line 1:                                                                                                                                

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

Where the installed.json file is empty.

When trying to initialize a package using composer init it generates an empty composer.json file.

@sbuzonas

This comment has been minimized.

Copy link
Contributor

sbuzonas commented Feb 26, 2015

How do you get an empty installed.json?

@budde377

This comment has been minimized.

Copy link
Author

budde377 commented Feb 26, 2015

When running composer install

@sbuzonas

This comment has been minimized.

Copy link
Contributor

sbuzonas commented Feb 26, 2015

What is your composer version? Do you have a sample composer.json that would result in an empty installed.json?

All I can manage to get is a [] entry in the file if I update to an empty set of packages. If you delete the installed.json do you continue to get the error?

@budde377

This comment has been minimized.

Copy link
Author

budde377 commented Feb 26, 2015

I'm currently experiencing this with all composer.json files. E.g. https://github.com/budde377/Part/blob/master/composer.json

The version is:

Composer version 1.0-dev (fb562ceb65afd6653020fd912ddfe5530a815869) 2015-02-17 10:50:55
@xabbuh

This comment has been minimized.

Copy link
Contributor

xabbuh commented Feb 26, 2015

@budde377 Does the issue persist after running composer self-update?

@Seldaek

This comment has been minimized.

Copy link
Member

Seldaek commented Feb 27, 2015

@budde377 I tried installing the composer.json you linked and it seems to work fine here, after it completes I can do composer show -i to see what's installed (from installed.json)

@Seldaek

This comment has been minimized.

Copy link
Member

Seldaek commented Feb 27, 2015

@budde377 can you update to latest (composer self-update) and then run composer show -s -vvv and paste the output? Just wondering if it is loading any plugins from your global composer dir that might interfere with composer.

@budde377

This comment has been minimized.

Copy link
Author

budde377 commented Mar 5, 2015

Further testing indicates that this is in fact not a problem with Composer. Rather a problem with the interpreter used, where json_encode would detect non-existing recursion.

@budde377 budde377 closed this Mar 5, 2015

@Seldaek

This comment has been minimized.

Copy link
Member

Seldaek commented Mar 5, 2015

@budde377 is there any way we could detect this an warn users? What interpreter/json_encode are you speaking of exactly?

@budde377

This comment has been minimized.

Copy link
Author

budde377 commented Mar 5, 2015

You could check if an error occurred after you generate the json, using json_last_error, or simply check if json_encode returns false. If that is the case, then throw an exception instead of creating the empty file.

I do however find it quite unlikely that other users are going to experience the same problem, since we were running an PHP 5.6.6 interpreter, modified to our studies.

@Seldaek

This comment has been minimized.

Copy link
Member

Seldaek commented Mar 5, 2015

Ah ha I see you hacked up PHP :) Still I guess it can't hurt to check json_encode's return value. Thanks for the details.

Seldaek added a commit that referenced this issue Mar 5, 2015

ChadSikorra added a commit to ChadSikorra/composer that referenced this issue Mar 28, 2015

@darthchudi

This comment has been minimized.

Copy link

darthchudi commented Oct 21, 2017

Hey, I'm presently having this exact same issue. Did you ever resolve it?

@oussaka

This comment has been minimized.

Copy link

oussaka commented Nov 11, 2017

I solved it with

rm -rf vendor/
then 
composer install
@rogeriopradoj

This comment has been minimized.

Copy link
Contributor

rogeriopradoj commented Jul 23, 2018

#3786 (comment)

I borrowed @oussaka comment and included it in a StackOverflow answer:

https://stackoverflow.com/questions/31248017/composer-does-not-contain-valid-json/51476527#51476527

Replying it here in order to help other users:

In windows machine, I've followed all these steps and get back in a correct behaviour (my problem was happening with composer require, but I believe it's the same as you described using composer search or if we would be using composer install for example. So, let´s see the steps:

  1. Update composer (`composer self-update)
  2. Disable IPV6 (as pointed in official docs, misconfigured IPV6 setting is a common source of issues)
  3. Delete (or rename to repo_temp) your folder %LOCALAPPDATA%\Composer\repo (in order to have all contents updated)
  4. Delete (or rename to vendor_temp) your vendor folder inside your project (in order to force composer to download all components again, and as pointed in this thread comment)

After doing these steps, in my, case, the issue was gone!

Message before (ERROR):

> composer require ...
...

"https://packagist.org/packages.json" does not contain valid JSON
Parse error on line 1:
▼\\\\\\♥��ݎ♀���
^
Expected one of: 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '['
https://packagist.org could not be fully loaded, package information was loaded from the local cache and may be out of date

Message after doing the steps (OK)!:

> composer require ...

...

Writing lock file
Generating autoload files
@jiromesarb

This comment has been minimized.

Copy link

jiromesarb commented Mar 15, 2019

Hi! I just encountered this when I use composer update and I accidentally shutdown my laptop while the composer is updating.

I found my installed.json file in vendor/composer that it's empty (a white space?). I looked for a copy of installed.json and pasted it on my project it worked again :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.