The phrase such as requires a comma in front of it only if it’s part of a nonrestrictive clause.
When to Use a Comma Before Such As
Here’s an example of such as used correctly with a comma in a sentence:
The phrase such as pine and spruce is nonrestrictive, so you need a comma. How can you tell it’s nonrestrictive?