Since it took a couple of centuries for a formal church to come into being, how could gnostics be heretical to a church and a doctrine that didn't exist?
The Church was formal from the very beginning. Christ appointed twelve apostles, gave them a specific office and delegated specific authority to them for the discharge of that office. Within weeks of the Resurrection the apostles had rules for succession to the apostolic office in place and local churches had episkopoi (bishops or overseers), presbyteroi (elders or priests) and diakonoi (deacons or helpers) in place while Paul was still alive. The Church obviously had organized missions across the Mediterranean world at that time and it also was able to coordinate almsgiving and other charitable works over a broad geographical area.
However, the Gnostics were already heretics before Jesus was born - they specifically rejected the status of the God of Abraham Isaac and Jacob as the one true God.
Gnostic cults at that time already held that the world was created by a evil subsidiary deity and that material creation itself was evil.
The Gnostics had already rejected the orthodox teaching of the book of Genesis before they were even able to begin distorting and falsifying Jesus' teaching.