How to solve the problem “No tokens were provided” when running di compile in magento 2

Some times you have the problem with error message “No tokens were provided” when you try to run ssh command line “php bin/magento┬ásetup:di:compile”:

[Zend\Code\Exception\RuntimeException]
No tokens were provided

You can find where throught this problem by using command line:

grep -lr 'No tokens were provided' vendor/

You will see the resuls:

vendor/zendframework/zend-code/src/Scanner/ConstantScanner.php
vendor/zendframework/zend-code/src/Scanner/TokenArrayScanner.php
vendor/zendframework/zend-code/src/Scanner/MethodScanner.php
vendor/zendframework/zend-code/src/Scanner/PropertyScanner.php
vendor/zendframework/zend-code/src/Scanner/ClassScanner.php
if (!$this->tokens) {
        throw new \Zend\Code\Exception\RuntimeException('No tokens were provided');
    }

This problem happens when there are some empty files in your website. You can solve it by delete those files by using command line:

find ./ -size 0 -delete

or

find ./ -type f -empty -delete

Now, please run di compile again. Hope it works fine.

Add Comment

Required fields are marked *. Your email address will not be published.