Clearing cache breaks site I'm trying to load a production site in a dev environment using the site's codebase (core 8.3.7, contrib and custom modules and vendor folder) and the current database.

After struggling a bit with it, I managed to import the DB (it's PGSQL with a lot of extensions), and the site was up. I looked into the status report page and besides a few update warnings, there are no errors.

First time I try to clear cache, the site breaks and starts complaining about missing modules (one of them made sense, the other is the basic_auth module, which is in core). I manually cleaned up the missing one from the DB, but I'm getting a log of PluginNotFoundExceptions, which to me, says I must have done something wrong. I've tried importing the DB again and I traced the caching issues down to router cache and views cache. All of the other caches are cleaned with no issues, but these two throw the above exceptions.

I've tried to install the codebase again via composer, respecting the .lock file with composer update --lock, and it says there is nothing to install/update. 

I'm a bit lost, and the only way I can make the site work (even if momentarily) is by importing the DB again, but it breaks after cache clearing and/or configurations being exported, either via drush or via backend.

AFAICT, even if the codebase was in fact missing something (ie, someone installed something in production not managed by composer), it would show up in the contrib folder and by importing the DB it should be fine, right?

Does anyone have some suggestions on where to start looking for the problem?
Are you sure there are no differences in the codebase? This would explain the issue. The plugins/routes are cached in the database until you clear the cache. Then they are rediscovered from the codebase and the missing plugins or routes become visible. It's not necessarily that the code is missing physically, it can also be a problem with autoloading. 

If there is a problem with syncing the codebase by git/composer, use another tool, for example rsync. Make sure to sync the complete codebase, also the files in the root folder.