However, Federer was made to work hard as he was taken to three sets (6-2, 4-6, 6-4 ) by the little known Serbian.
Finland-born home player Henri Laaksonen won his first match in Basel after five previous first-round losses, beating Roland Garros semi-finalist and sixth seed Marco Cecchinato 6-4, 6-2.
The second set stayed on serve until a fifth double-fault from Struff, which opened the door for Federer to move 6-5 ahead.
Federer revealed in the run-up to the start at the St Jakobshalle that he had been suffering since the summer with a hand injury, which the 20-time Grand Slam victor insisted was fine now.
"It was a lot of rocky start, I had to clean up my game, I'm happy about that", Federer said.
Markets Right Now: Wall Street is rocked by more selling
Bond prices rose, sending the yield on the 10-year Treasury note down to 3.11 per cent from 3.16 per cent late Tuesday. Amazon and Alphabet, both scheduled to report earnings on Thursday, fell by more than 5 percent each on Wednesday.
"There was no rhythm, it was a sprint on the majority of points".
Fourth seed Stefanos Tsitsipas, who last week became the first Greek to win an ATP title when he triumphed in Stockholm, swept aside Germany's Peter Gojowczyk 6-3 6-1 to continue his impressive season.
In his tournament debut, Australian John Millman faces Germany's Jan-Lennard Struff first up with the victor progressing to a meeting with Federer or Krajinovic. "But maybe that's exactly what caught up to me eventually", said the Swiss maestro in his post match conference. "I think the rivalry between the young guys right now may be even stronger than that of the big names". He also reached his first Masters final in Toronto in August before losing to Rafael Nadal.
Australian Open runner-up Cilic is one of two former champions in the draw, alongside Federer, and he brushed aside teenager Shapovalov 6-4, 6-2. In-form Russian seventh seed Daniil Medvedev also reached the last 16 by defeating German Maximilian Marterer 6-3 7-5.