即使文件存在,Composer 也找不到 composer.json 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21414545/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Composer could not find a composer.json file even when the file exists
提问by Stacy J
I have installed Laravel and and I am playing around with it.
我已经安装了 Laravel,并且正在使用它。
I am following the tutorial :-
我正在学习教程:-
http://geekanddummy.com/how-to-laravel-4-tutorial-part-3-using-external-libraries/
http://geekanddummy.com/how-to-laravel-4-tutorial-part-3-using-external-libraries/
I need a new library and have added that in composer.json.
我需要一个新库,并在 composer.json 中添加了它。
But when I run
但是当我跑
php composer.phar update
I get the following message :-
我收到以下消息:-
Composer could not find a composer.json file in
What do I need to do to get this corrected..?
我需要做什么才能纠正这个问题..?
回答by Rob Pomeroy
I'm the author of the tutorial you link to (hope our Laravel tutorial seriesis of some use, by the way). I can't quite tell from your answer whether you restored all the content of the original composer.json file when you created a new file of the same name...? You definitely shouldn't need to nuke the composer.json file and start again. As you probably know, that file contains all the Composer-based dependencies for your Laravel project, so you would of course lose significant functionality if you were to wipe it and leave anything out when you start again.
我是您链接到的教程的作者(顺便说一下,希望我们的Laravel 教程系列对您有所帮助)。我无法从您的回答中完全判断您在创建同名新文件时是否恢复了原始 composer.json 文件的所有内容......?您绝对不需要核对 composer.json 文件并重新开始。您可能知道,该文件包含 Laravel 项目的所有基于 Composer 的依赖项,因此如果您在重新开始时擦除它并遗漏任何内容,您当然会失去重要的功能。
The error message looks to me like you're either in the wrong directory or it's a permissions problem with the composer.json file. It's too late to be certain now, but if you come across the problem again, try running:
错误消息在我看来就像您位于错误的目录中,或者是 composer.json 文件的权限问题。现在确定为时已晚,但是如果您再次遇到问题,请尝试运行:
chmod a+r composer.json
at the console/ssh shell before running composer update. This restores read permissions (for all users). You may also wish to check file ownership. (Both commands assume we're in a Unix/Linux system, so YMMV.)
在运行composer update. 这将恢复读取权限(对于所有用户)。您可能还希望检查文件所有权。(这两个命令都假设我们在 Unix/Linux 系统中,所以 YMMV。)
Watch out also for instances where you're running a Composer command with the globalparameter. This will cause an change that relates to wherever you've installed Composer, rather than the directory you're currently working in.
还要注意您使用global参数运行 Composer 命令的情况。这将导致与您安装 Composer 的位置相关的更改,而不是您当前工作的目录。
Note that you can also update using the --working-dirparameter, thus:
请注意,您还可以使用--working-dir参数进行更新,因此:
php composer.phar --working-dir=/path/to/laravel/project update
Hope this helps.
希望这可以帮助。
Rob
抢
回答by Stacy J
Deleting the existing composer.json after copying the content and then saving a new file with the same name works.
复制内容后删除现有的 composer.json 并保存同名的新文件。
回答by Steve Bauman
If your on windows (at least in my experience) you actually use just 'composer', not composer.phar/.json or any extension.
如果您在 Windows 上(至少以我的经验),您实际上只使用“composer”,而不是 composer.phar/.json 或任何扩展名。
composer update
composer dump-autoload
This is all I need to type in to be able to access composer in my laravel directory.
这是我需要输入的全部内容才能访问我的 laravel 目录中的 composer。
回答by Gunnrryy
i had the same issue, tried several many solutions that worked for others but not in my case. then some-one told me to drop the 'php' and '.phar' from my command. i.e. directly use
我遇到了同样的问题,尝试了多种对其他人有效但不适用于我的解决方案。然后有人告诉我从我的命令中删除“php”和“.phar”。即直接使用
composer update composer create-project etc.etc.
作曲家更新作曲家创建项目等。
and to my surprise it worked..
令我惊讶的是它奏效了..
回答by Kay V
Occasionally, and for reasons that remain a bit vague, restarting the server seems to solve the issue. That step might be worth trying before making changes to file permissions.
有时,由于仍然有些模糊的原因,重新启动服务器似乎可以解决问题。在更改文件权限之前,该步骤可能值得尝试。

