I don’t know why shuffle=True should raise the error only, as it seems that your dataset might be empty.
While creating the DataLoader a RandomSampler or SequentialSampler will be created if shuffle is set to True or False, respectively, and no custom sampler is passed as seen here 1.
In both cases the length of the data_source will be used (in your case the dataset) here 1 or here 1 so I would assume that both use cases fail if the dataset is empty.
Could you check print(len(dataset)) before passing it to the DataLoader and make sure it has a valid length?