A railcar hauling lithium ion batteries caught fire early Wednesday, prompting the closure of Cajon Boulevard through the Cajon Pass, officials said.