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

Fatal error: Uncaught Error: Class 'think\Console' not found #41

Open
sorry510 opened this issue Apr 21, 2020 · 2 comments
Open

Fatal error: Uncaught Error: Class 'think\Console' not found #41

sorry510 opened this issue Apr 21, 2020 · 2 comments

Comments

@sorry510
Copy link

sorry510 commented Apr 21, 2020

我使用的tp版本为5.1think-migration版本为2.0.3,这个库本身使用没有问题,但是会导致其它库的脚本无法执行,我使用这个库(captainhook/captainhook)时,此库需要使用自动加载加载文件,执行cli的脚本,但是当require vendor/autoload.php
库的源码如下

 // check installation type [composer bin dir, git clone / phar, composer package dir]
    $composerAutoloadLocations = [
        __DIR__ . '/../autoload.php',
        __DIR__ . '/../vendor/autoload.php',
        __DIR__ . '/../../../autoload.php'
    ];

    foreach ($composerAutoloadLocations as $file) {
        if (file_exists($file)) {
            define('CAPTAINHOOK_COMPOSER_AUTOLOAD', $file);
            break;
        }
    }
    unset($file);

    if (!defined('CAPTAINHOOK_COMPOSER_AUTOLOAD')) {
        fwrite(STDERR,
            'You need to set up the project dependencies using the following commands:' . PHP_EOL .
            'wget http://getcomposer.org/composer.phar' . PHP_EOL .
            'php composer.phar install' . PHP_EOL
        );
        exit(1);
    }

    require CAPTAINHOOK_COMPOSER_AUTOLOAD;

就会报如下错误,不光是这个库,我试了凡是用的自动加载的都会报错,这个应该是think-migration库的问题,我单独试了这个库没有问题,在laravel试了也没有问题

Fatal error: Uncaught Error: Class 'think\Console' not found in E:\UPUPW_NP7.2_64\vhosts\contract_tp5.1\vendor\topthink\think-migration\src\config.php on line 10

config.php的文件源码如下,为什么使用自动加载会无法加载到think\Console这个类呢,希望能修复这个bug


\think\Console::addDefaultCommands([
    "think\\migration\\command\\migrate\\Create",
    "think\\migration\\command\\migrate\\Run",
    "think\\migration\\command\\migrate\\Rollback",
    "think\\migration\\command\\migrate\\Breakpoint",
    "think\\migration\\command\\migrate\\Status",
    "think\\migration\\command\\seed\\Create",
    "think\\migration\\command\\seed\\Run",
]);
@pifeifei
Copy link

pifeifei commented Jun 19, 2020

我也遇到了,问题解决

原因:

  • composer 不支持 composer.json 中的 extra.think-path 配置
  • 只有 thinkphp 5.1 存在这个问题,5.2, 6.0 不存在这个问

解决:

cd /path/to/thinkphp5.1 #或其他 thinkphp 版本目录

# window
mklink /j  vendor\topthink\framework thinkphp
# linux
ln -s thinkphp vendor/topthink/framework
# 运行不再报错
composer dumpautoload

PS:如想要彻底解决需要些脚本自动创建对应软连接

@sorry510
Copy link
Author

我也遇到了,问题解决

原因:

  • composer 不支持 composer.json 中的 extra.think-path 配置
  • 只有 thinkphp 5.1 存在这个问题,5.2, 6.0 不存在这个问

解决:

cd /path/to/thinkphp5.1 #或其他 thinkphp 版本目录

# window
mklink /j  vendor\topthink\framework thinkphp
# linux
ln -s thinkphp vendor/topthink/framework
# 运行不再报错
composer dumpautoload

PS:如想要彻底解决需要些脚本自动创建对应软连接

我用5.1试了还是不行

xcorp1986 pushed a commit to xcorp1986/think-migration that referenced this issue Jan 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants