I just had this problem, and all I had to do was making sure you're referencing your matSort viewChild correctly and make sure you have added the MatSortModule in your module.ts file in the imports area.
Like the following:
@NgModule({
imports: [
MatSortModule,
MatTableModule,
]
)}