I had this problem. What worked was replacing the "truffle-hdwallet-provider" in the require method argument at here: const HDWalletProvider = require('truffle-hdwallet-provider');
with @truffle/hdwallet-provider
const HDWalletProvider = require('@truffle/hdwallet-provider');
and truffle compile
finally worked.
But make sure you install it first: run this first:
$ npm install @truffle/hdwallet-provider