Adding #include <SPI.h> solved the issue. Could you please explain why it worked? Thank you!
#include <SPI.h>