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.