Preheat the oven to 350°F. Lightly grease a 9×13-inch baking dish.
Spread 2 cups freshly shredded carrots evenly over the bottom of the prepared dish.
Spoon 1 (20-ounce) can crushed pineapple, including the juice, evenly over the carrots.
Drizzle 1 (14-ounce) can sweetened condensed milk evenly over the pineapple layer.
Sprinkle 1 box dry spice cake mix evenly over the top. Do not stir.
Sprinkle 1/2 to 1 cup chopped pecans or walnuts evenly over the cake mix if using.
Arrange 1/2 cup (1 stick) thinly sliced butter evenly across the surface, covering as much of the dry cake mix as possible so it browns evenly.
Bake for 45–55 minutes, or until the top is golden brown and the filling is bubbling around the edges.
Let the cake cool slightly. Microwave the cream cheese frosting in 15-second intervals until pourable, then drizzle the frosting over the warm cake before serving.