They used their nicknames in public.
A gang of chattering girls separated Snape from James, Sirius
and Lupin, and by planting himself in their midst, Harry managed
to keep Snape in sight while straining his ears to catch the voices
of James and his friends.
‘Did you like question ten, Moony?’ asked Sirius as they emerged
into the Entrance Hall.
—Harry Potter and the Order of the Phoenix
Slightly after:
Behind him, the Impediment Jinx was wearing off. Snape was
beginning to inch towards his fallen wand, spitting out soapsuds
as he crawled.
‘I wouldn’t go out with you if it was a choice between you and
the giant squid,’ said Lily.
‘Bad luck, Prongs,’ said Sirius briskly, and turned back to Snape.
‘OI!’
—Harry Potter and the Order of the Phoenix
Snape was clearly in hearing range to know that James' nickname was Prongs. Whether he had ever heard the others nicknames doesn't matter to much since Prongs would have instantly linked the map to James, Lupin, Sirius, and Peter.
But Sirius seems quite cavalier about using their nicknames in public so its pretty safe to say he knew all 4 of their nicknames.
@everyone whose confused about Snape
‘Indeed?’ said Snape. His jaw had gone rigid with anger. ‘You
think a joke-shop could supply him with such a thing? You don’t
think it more likely that he got it directly from the manufacturers?’
Harry didn’t understand what Snape was talking about. Nor,
apparently, did Lupin.
‘You mean, from Mr Wormtail or one of these people?’ he said.
‘Harry, do you know any of these men?’
[...]
‘Why did Snape think I’d got it from the manufacturers?’
‘Because ...’ Lupin hesitated, ‘because these mapmakers would have
wanted to lure you out of school. They’d think it extremely
entertaining.’
‘Do you know them?’ said Harry, impressed.
‘We’ve met,’ he said shortly.He was looking at Harry more seriously than ever before.
—Harry Potter and the Prisoner of Azkaban
Here, on top of the nicknames, the text in book 3 itself indicates that Snape believed Lupin to be the manufacturer to begin with, but just can't prove it.